• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2016-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
3  */
4 
5 package kotlinx.atomicfu.gradle.plugin.test.cases.smoke
6 
7 import kotlinx.atomicfu.gradle.plugin.test.framework.checker.ArtifactChecker
8 import java.io.File
9 import java.nio.file.Files
10 import kotlin.test.*
11 import kotlin.text.*
12 
13 class ArtifactCheckerSmokeTest {
14     val tempDir = Files.createTempDirectory("sample").toFile()
15 
16     private class MyArtifactChecker(tempDir: File) : ArtifactChecker(tempDir) {
17         private val atomicfuString = "public final void doWork(int);\n" +
18                 "    descriptor: (I)V\n" +
19                 "    flags: (0x0011) ACC_PUBLIC, ACC_FINAL\n" +
20                 "    Code:\n" +
21                 "      stack=3, locals=2, args_size=2\n" +
22                 "         0: aload_0\n" +
23                 "         1: getfield      #18                 // Field _x:Lkotlinx/atomicfu/AtomicInt;\n" +
24                 "         4: iconst_0\n" +
25                 "         5: sipush        556\n" +
26                 "         8: invokevirtual #28                 // Method kotlinx/atomicfu/AtomicInt.compareAndSet:(II)Z\n" +
27                 "        11: pop\n" +
28                 "        12: return\n" +
29                 "      LineNumberTable:\n" +
30                 "        line 14: 0\n" +
31                 "        line 19: 12\n" +
32                 "      LocalVariableTable:\n" +
33                 "        Start  Length  Slot  Name   Signature\n" +
34                 "            0      13     0  this   LIntArithmetic;\n" +
35                 "            0      13     1 finalValue   I"
36 
37 
38         val noAtomicfuString = "  public final void doWork(int);\n" +
39                 "    descriptor: (I)V\n" +
40                 "    flags: (0x0011) ACC_PUBLIC, ACC_FINAL\n" +
41                 "    Code:\n" +
42                 "      stack=4, locals=2, args_size=2\n" +
43                 "         0: aload_0\n" +
44                 "         1: getstatic     #22                 // Field _x\$FU:Ljava/util/concurrent/atomic/AtomicIntegerFieldUpdater;\n" +
45                 "         4: swap\n" +
46                 "         5: iconst_0\n" +
47                 "         6: sipush        556\n" +
48                 "         9: invokevirtual #28                 // Method java/util/concurrent/atomic/AtomicIntegerFieldUpdater.compareAndSet:(Ljava/lang/Object;II)Z\n" +
49                 "        12: pop\n" +
50                 "        13: return\n" +
51                 "      LineNumberTable:\n" +
52                 "        line 14: 0\n" +
53                 "        line 19: 13\n" +
54                 "      LocalVariableTable:\n" +
55                 "        Start  Length  Slot  Name   Signature\n" +
56                 "            0      14     0  this   LIntArithmetic;\n" +
57                 "            0      14     1 finalValue   I"
58 
59         val metadataString = "RuntimeVisibleAnnotations:\n" +
60                 "  0: #32(#33=[I#34,I#35,I#36],#37=I#34,#38=I#39,#40=[s#41],#42=[s#20,s#43,s#6,s#15,s#16,s#21,s#43,s#29,s#43,s#44])\n" +
61                 "    kotlin.Metadata(\n" +
62                 "      mv=[1,9,0]\n" +
63                 "      k=1\n" +
64                 "      xi=48\n" +
65                 "      d1=[\"\\u0000\\u001e\\n\\u0002\\u0018\\u0002\\n\\u0002\\u0010\\u0000\\n\\u0002\\b\\u0002\\n\\u0002\\u0018\\u0002\\n\\u0000\\n\\u0002\\u0010\\u0002\\n\\u0000\\n\\u0002\\u0010\\b\\n\\u0000\\u0018\\u00002\\u00020\\u0001B\\u0005¢\\u0006\\u0002\\u0010\\u0002J\\u000e\\u0010\\u0005\\u001a\\u00020\\u00062\\u0006\\u0010\\u0007\\u001a\\u00020\\bR\\u000e\\u0010\\u0003\\u001a\\u00020\\u0004X\\u0082\\u0004¢\\u0006\\u0002\\n\\u0000¨\\u0006\\t\"]\n" +
66                 "      d2=[\"LIntArithmetic;\",\"\",\"()V\",\"_x\",\"Lkotlinx/atomicfu/AtomicInt;\",\"doWork\",\"\",\"finalValue\",\"\",\"jvm-sample\"]\n" +
67                 "    )"
68 
checkReferencesnull69         override fun checkReferences() {
70             assertTrue(atomicfuString.toByteArray().findAtomicfuRef())
71             assertFalse(noAtomicfuString.toByteArray().findAtomicfuRef())
72             assertTrue(metadataString.toByteArray().findAtomicfuRef())
73         }
74     }
75 
76     private val checker = MyArtifactChecker(tempDir)
77 
78     @Test
testAtomicfuReferenciesLookupnull79     fun testAtomicfuReferenciesLookup() {
80         checker.checkReferences()
81     }
82 }
83