Skip to content

Commit 5bd76b2

Browse files
committed
[comgr] Add test for multiple note sections in a code object
Change-Id: I4599afcc56cb31c766784bca787df163ea003911
1 parent 55bc138 commit 5bd76b2

File tree

8 files changed

+834
-1
lines changed

8 files changed

+834
-1
lines changed

amd/comgr/docs/ReleaseNotes.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ where reporters provide Comgr logs.
152152
- Update default arch for test binaries from gfx830 to gfx900
153153
- Refactor nested kernel behavior into new test, as this behavior is less common
154154
and shouldn't be featured in the baseline tests
155+
- Add metadata parsing tests for code objects with multiple AMDGPU metadata note entries.
155156

156157
New Targets
157158
-----------

amd/comgr/test/CMakeLists.txt

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ set(TEST_INPUT_BINARIES)
22
set(TEST_INPUT_BITCODES)
33
set(TEST_INPUT_BUNDLES)
44
set(TEST_INPUT_ARCHIVES)
5+
set(TEST_INPUT_LINKED_OBJS)
6+
57
# Create target ${name} which depends on a clang command to compile ${input} to
68
# ${output}, with any additional arguments from ${ARGN}, and add it to the
79
# TEST_INPUT_BINARIES target list.
@@ -86,13 +88,40 @@ macro(add_test_archive name target input output)
8688
list(APPEND TEST_INPUT_ARCHIVES "${name}")
8789
endmacro()
8890

91+
# Creates target ${name} which depends on 2 clang commands to compile
92+
# ${input0} and ${input1} and then links them to create ${output}
93+
# with any additional arguments from ${ARGN}, and add it to the
94+
# TEST_INPUT_LINKED_OBJS target list.
95+
macro(add_test_input_linked name input0 input1 output)
96+
add_custom_command(
97+
OUTPUT "${output}"
98+
COMMAND "$<TARGET_FILE:lld>" -flavor gnu ${ARGN} "${input0}"
99+
"${input1}" -o "${output}"
100+
VERBATIM
101+
DEPENDS lld "${input0}" "${input1}")
102+
add_custom_target("${name}"
103+
DEPENDS "${output}"
104+
SOURCES "${input0}" "${input1}")
105+
list(APPEND TEST_INPUT_LINKED_OBJS "${name}")
106+
endmacro()
107+
89108
add_test_input_binary(reloc1 source/reloc1.cl source/reloc1.o -c -mcode-object-version=4)
90109
add_test_input_binary(reloc2 source/reloc2.cl source/reloc2.o -c -mcode-object-version=4)
91110
add_test_input_binary(reloc-asm source/reloc-asm.s source/reloc-asm.o -c -mcode-object-version=4)
92111
add_test_input_binary(shared source/shared.cl source/shared.so -mcode-object-version=4)
93112
add_test_input_binary(shared-debug source/shared.cl source/shared-debug.so -g -mcode-object-version=4)
94113
add_test_input_bitcode(source1 source/source1.cl source/source1.bc)
95114

115+
add_test_input_binary(linking-kernel0 source/linking/kernel0.cl source/linking/kernel0.o -c -mcode-object-version=4)
116+
add_test_input_binary(linking-kernel1 source/linking/kernel1.cl source/linking/kernel1.o -c -mcode-object-version=4)
117+
add_test_input_binary(linking-empty source/linking/empty.cl source/linking/empty.o -c -mcode-object-version=4)
118+
119+
add_test_input_linked(multiple-note-records source/linking/kernel0.o source/linking/kernel1.o source/multiple-note-records.out)
120+
add_test_input_linked(multiple-note-records-one-kernel source/linking/kernel0.o source/linking/empty.o source/multiple-note-records-one-kernel.out)
121+
122+
configure_file("source/linking/kernel0.cl" "source/linking/kernel0.cl" COPYONLY)
123+
configure_file("source/linking/kernel1.cl" "source/linking/kernel1.cl" COPYONLY)
124+
configure_file("source/linking/empty.cl" "source/linking/empty.cl" COPYONLY)
96125
configure_file("source/source1.cl" "source/source1.cl" COPYONLY)
97126
configure_file("source/source2.cl" "source/source2.cl" COPYONLY)
98127
configure_file("source/nested-kernel1.cl" "source/nested-kernel1.cl" COPYONLY)
@@ -156,7 +185,7 @@ endif()
156185
amd_comgr)
157186
add_dependencies("${name}"
158187
${TEST_INPUT_BINARIES};${TEST_INPUT_BITCODES};${TEST_INPUT_BUNDLES};
159-
${TEST_INPUT_ARCHIVES})
188+
${TEST_INPUT_ARCHIVES};${TEST_INPUT_LINKED_OBJS})
160189
add_test(NAME ${test_name}
161190
COMMAND "${name}")
162191
add_dependencies(check-comgr ${name})
@@ -178,6 +207,7 @@ add_comgr_test(disasm_options_test c)
178207
add_comgr_test(metadata_tp_test c)
179208
add_comgr_test(metadata_yaml_test c)
180209
add_comgr_test(metadata_msgpack_test c)
210+
add_comgr_test(metadata_multiple_msgpacks_test c)
181211
add_comgr_test(metadata_merge_test c)
182212
add_comgr_test(symbols_test c)
183213
add_comgr_test(symbols_iterate_test c)
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
2+
#include "amd_comgr.h"
3+
#include "common.h"
4+
#include <stdio.h>
5+
#include <stdlib.h>
6+
#include <string.h>
7+
8+
typedef struct test_meta_data_s {
9+
char *Buf;
10+
amd_comgr_data_t Data;
11+
amd_comgr_metadata_node_t Root;
12+
} test_meta_data_t;
13+
14+
void read_metadata(test_meta_data_t *MetaData, const char *File, bool IsErr) {
15+
long Size;
16+
amd_comgr_status_t Status;
17+
amd_comgr_metadata_kind_t Mkind = AMD_COMGR_METADATA_KIND_NULL;
18+
19+
// Read input file
20+
char Buffer[1024];
21+
snprintf(Buffer, 1024, "%s/%s", TEST_OBJ_DIR, File);
22+
Size = setBuf(Buffer, &MetaData->Buf);
23+
24+
Status =
25+
amd_comgr_create_data(AMD_COMGR_DATA_KIND_RELOCATABLE, &MetaData->Data);
26+
checkError(Status, "amd_comgr_create_data");
27+
28+
Status = amd_comgr_set_data(MetaData->Data, Size, MetaData->Buf);
29+
checkError(Status, "amd_comgr_set_data");
30+
31+
Status = amd_comgr_set_data_name(MetaData->Data, NULL);
32+
checkError(Status, "amd_comgr_set_data_name");
33+
34+
// Get metadata from data object
35+
printf("Get metadata from %s\n", File);
36+
37+
Status = amd_comgr_get_data_metadata(MetaData->Data, &MetaData->Root);
38+
checkError(Status, "amd_comgr_get_data_metadata");
39+
40+
// the root must be map
41+
Status = amd_comgr_get_metadata_kind(MetaData->Root, &Mkind);
42+
checkError(Status, "amd_comgr_get_metadata_kind");
43+
if (Mkind != AMD_COMGR_METADATA_KIND_MAP) {
44+
printf("Root is not map\n");
45+
exit(1);
46+
}
47+
48+
// iterate code object metadata
49+
int Indent = 0;
50+
printf("Metadata for file %s : start\n", File);
51+
Status = amd_comgr_iterate_map_metadata(MetaData->Root, printEntry,
52+
(void *)&Indent);
53+
if (Status) {
54+
if (IsErr)
55+
return;
56+
checkError(Status, "amd_comgr_iterate_map_metadata");
57+
} else if (IsErr) {
58+
printf("Unexpected success from amd_comgr_iterate_map_metadata\n");
59+
exit(1);
60+
}
61+
printf("Metadata for file %s : end\n\n", File);
62+
}
63+
64+
void close_meta_data(test_meta_data_t *MetaData) {
65+
amd_comgr_status_t Status;
66+
67+
Status = amd_comgr_destroy_metadata(MetaData->Root);
68+
checkError(Status, "amd_comgr_destroy_metadata");
69+
70+
Status = amd_comgr_release_data(MetaData->Data);
71+
checkError(Status, "amd_comgr_release_data");
72+
free(MetaData->Buf);
73+
74+
memset(MetaData, 0, sizeof(test_meta_data_t));
75+
}
76+
77+
int main(int argc, char *argv[]) {
78+
test_meta_data_t MetaData;
79+
80+
memset(&MetaData, 0, sizeof(test_meta_data_t));
81+
82+
#define READ_METADATA(meta, file, is_error) \
83+
do { \
84+
read_metadata(&meta, file, is_error); \
85+
close_meta_data(&meta); \
86+
} while (0)
87+
88+
READ_METADATA(MetaData, "multiple-note-records.out", false);
89+
READ_METADATA(MetaData, "multiple-note-records-one-kernel.out", false);
90+
91+
printf("Metadata Multiple MsgPacks tests : passed\n");
92+
return 0;
93+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*******************************************************************************
2+
*
3+
* University of Illinois/NCSA
4+
* Open Source License
5+
*
6+
* Copyright (c) 2024 Advanced Micro Devices, Inc. All Rights Reserved.
7+
*
8+
* Permission is hereby granted, free of charge, to any person obtaining a copy
9+
* of this software and associated documentation files (the "Software"), to deal
10+
* with the Software without restriction, including without limitation the
11+
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
12+
* sell copies of the Software, and to permit persons to whom the Software is
13+
* furnished to do so, subject to the following conditions:
14+
*
15+
* * Redistributions of source code must retain the above copyright notice,
16+
* this list of conditions and the following disclaimers.
17+
*
18+
* * Redistributions in binary form must reproduce the above copyright
19+
* notice, this list of conditions and the following disclaimers in the
20+
* documentation and/or other materials provided with the distribution.
21+
*
22+
* * Neither the names of Advanced Micro Devices, Inc. nor the names of its
23+
* contributors may be used to endorse or promote products derived from
24+
* this Software without specific prior written permission.
25+
*
26+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
27+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
28+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
29+
* CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
30+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
31+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH
32+
* THE SOFTWARE.
33+
*
34+
*******************************************************************************/
35+
36+
void foo() {}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*******************************************************************************
2+
*
3+
* University of Illinois/NCSA
4+
* Open Source License
5+
*
6+
* Copyright (c) 2024 Advanced Micro Devices, Inc. All Rights Reserved.
7+
*
8+
* Permission is hereby granted, free of charge, to any person obtaining a copy
9+
* of this software and associated documentation files (the "Software"), to deal
10+
* with the Software without restriction, including without limitation the
11+
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
12+
* sell copies of the Software, and to permit persons to whom the Software is
13+
* furnished to do so, subject to the following conditions:
14+
*
15+
* * Redistributions of source code must retain the above copyright notice,
16+
* this list of conditions and the following disclaimers.
17+
*
18+
* * Redistributions in binary form must reproduce the above copyright
19+
* notice, this list of conditions and the following disclaimers in the
20+
* documentation and/or other materials provided with the distribution.
21+
*
22+
* * Neither the names of Advanced Micro Devices, Inc. nor the names of its
23+
* contributors may be used to endorse or promote products derived from
24+
* this Software without specific prior written permission.
25+
*
26+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
27+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
28+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
29+
* CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
30+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
31+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH
32+
* THE SOFTWARE.
33+
*
34+
*******************************************************************************/
35+
36+
void kernel kernel0(__global int *j) {
37+
*j += 2;
38+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*******************************************************************************
2+
*
3+
* University of Illinois/NCSA
4+
* Open Source License
5+
*
6+
* Copyright (c) 2024 Advanced Micro Devices, Inc. All Rights Reserved.
7+
*
8+
* Permission is hereby granted, free of charge, to any person obtaining a copy
9+
* of this software and associated documentation files (the "Software"), to deal
10+
* with the Software without restriction, including without limitation the
11+
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
12+
* sell copies of the Software, and to permit persons to whom the Software is
13+
* furnished to do so, subject to the following conditions:
14+
*
15+
* * Redistributions of source code must retain the above copyright notice,
16+
* this list of conditions and the following disclaimers.
17+
*
18+
* * Redistributions in binary form must reproduce the above copyright
19+
* notice, this list of conditions and the following disclaimers in the
20+
* documentation and/or other materials provided with the distribution.
21+
*
22+
* * Neither the names of Advanced Micro Devices, Inc. nor the names of its
23+
* contributors may be used to endorse or promote products derived from
24+
* this Software without specific prior written permission.
25+
*
26+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
27+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
28+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
29+
* CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
30+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
31+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH
32+
* THE SOFTWARE.
33+
*
34+
*******************************************************************************/
35+
36+
void kernel kernel1(__global int *j) {
37+
*j += 2;
38+
}

0 commit comments

Comments
 (0)