github.com/pyroscope-io/pyroscope@v0.37.3-0.20230725203016-5f6947968bd0/pkg/convert/jfr/parser_jvm_generated_class_merge_test.go (about)

     1  package jfr
     2  
     3  import (
     4  	"github.com/onsi/ginkgo/v2"
     5  	. "github.com/onsi/gomega"
     6  )
     7  
     8  var _ = ginkgo.Describe("mergeJVMGeneratedClasses", func() {
     9  	ginkgo.When("we parse jfr", func() {
    10  		ginkgo.When("we process jvm generated classes", func() {
    11  			testcases := [][]string{
    12  				{
    13  					"org/example/rideshare/EnclosingClass$$Lambda$4/1283928880",
    14  					"org/example/rideshare/EnclosingClass$$Lambda$_",
    15  				},
    16  				{
    17  					"org/example/rideshare/EnclosingClass$$Lambda$8/0x0000000800c01220",
    18  					"org/example/rideshare/EnclosingClass$$Lambda$_",
    19  				},
    20  				{
    21  					"java/util/concurrent/Executors$RunnableAdapter",
    22  					"java/util/concurrent/Executors$RunnableAdapter",
    23  				},
    24  				{
    25  					"jdk/internal/reflect/GeneratedMethodAccessor31",
    26  					"jdk/internal/reflect/GeneratedMethodAccessor_",
    27  				},
    28  			}
    29  			for _, testcase := range testcases {
    30  				src := testcase[0]
    31  				expectedRes := testcase[1]
    32  				ginkgo.It("merges so names - "+src, func() {
    33  					res := mergeJVMGeneratedClasses(src)
    34  					Expect(res).To(Equal(expectedRes))
    35  				})
    36  			}
    37  		})
    38  		ginkgo.When("we process shared libraries names", func() {
    39  			testcases := [][]string{
    40  				{
    41  					"libasyncProfiler-linux-arm64-17b9a1d8156277a98ccc871afa9a8f69215f92.so",
    42  					"libasyncProfiler-_.so",
    43  				},
    44  				{
    45  					"libasyncProfiler-linux-musl-x64-17b9a1d8156277a98ccc871afa9a8f69215f92.so",
    46  					"libasyncProfiler-_.so",
    47  				},
    48  				{
    49  					"libasyncProfiler-linux-x64-17b9a1d8156277a98ccc871afa9a8f69215f92.so",
    50  					"libasyncProfiler-_.so",
    51  				},
    52  				{
    53  					"libasyncProfiler-macos-17b9a1d8156277a98ccc871afa9a8f69215f92.so",
    54  					"libasyncProfiler-_.so",
    55  				},
    56  				{
    57  					"libamazonCorrettoCryptoProvider109b39cf33c563eb.so",
    58  					"libamazonCorrettoCryptoProvider_.so",
    59  				},
    60  				{
    61  					"amazonCorrettoCryptoProviderNativeLibraries.7382c2f79097f415/libcrypto.so",
    62  					"libamazonCorrettoCryptoProvider_.so",
    63  				},
    64  				{
    65  					"amazonCorrettoCryptoProviderNativeLibraries.24e42b0d5ecf5f50/libamazonCorrettoCryptoProvider.so",
    66  					"libamazonCorrettoCryptoProvider_.so",
    67  				},
    68  				{
    69  					"libzstd-jni-1.5.1-16931311898282279136.so",
    70  					"libzstd-jni-_.so",
    71  				},
    72  			}
    73  			for _, testcase := range testcases {
    74  				src := testcase[0]
    75  				expectedRes := testcase[1]
    76  				ginkgo.It("merges generated so names - "+src, func() {
    77  					res := mergeJVMGeneratedClasses(src)
    78  					Expect(res).To(Equal(expectedRes))
    79  				})
    80  				ginkgo.It("merges generated so names even deleted - "+src, func() {
    81  					res := mergeJVMGeneratedClasses(src + " (deleted)")
    82  					Expect(res).To(Equal(expectedRes))
    83  				})
    84  				ginkgo.It("merges generated so names even deleted inside with /tmp prefix - "+src, func() {
    85  					res := mergeJVMGeneratedClasses("/tmp/" + src + " (deleted)")
    86  					Expect(res).To(Equal(expectedRes))
    87  				})
    88  				ginkgo.It("merges generated so names even deleted inside with ./tmp prefix - "+src, func() {
    89  					res := mergeJVMGeneratedClasses("./tmp/" + src + " (deleted)")
    90  					Expect(res).To(Equal(expectedRes))
    91  				})
    92  			}
    93  		})
    94  	})
    95  })