-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[libc] created integration tests for newhdrgen #97361
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
efd4b95
[libc] created integration tests for hdrgen
aaryanshukla f86c14b
[libc] created integration tests for hdrgen
aaryanshukla 722a2ee
fixed formatting
aaryanshukla 62b6d62
clang formatter on string.h
aaryanshukla 80650e0
using small testing files instead
aaryanshukla e104bc3
fixed formatting
aaryanshukla 1faa3fa
fixed formatting and fixed header.py for format
aaryanshukla 900e891
added CMakeLists.txt for testing
aaryanshukla c3cd6ff
black formatting and changed comment area
aaryanshukla 0876dbb
fixed cmakelists
aaryanshukla 45975aa
added full-build mode for newhdrgen
aaryanshukla 6d89c0c
deleted change in enumeration.py
aaryanshukla 231874e
fixed spacing for header.py
aaryanshukla d65081e
fixed header.py for spacing
aaryanshukla 405cc52
removed file location helper in CMakeLists
aaryanshukla f9619ac
added testing for guard and attributes
aaryanshukla 36332e3
removed full_build check in cmakelists
aaryanshukla File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
if(LLVM_LIBC_FULL_BUILD) | ||
|
||
enable_testing() | ||
|
||
set(NEWHDGEN_TESTS_DIR ${CMAKE_CURRENT_SOURCE_DIR}/tests) | ||
|
||
add_test( | ||
NAME newhdrgen_integration_test | ||
COMMAND ${CMAKE_COMMAND} -E env PYTHONPATH=${CMAKE_CURRENT_SOURCE_DIR} python3 ${NEWHDGEN_TESTS_DIR}/test_integration.py | ||
) | ||
|
||
add_custom_target(check-newhdrgen | ||
COMMAND ${CMAKE_CTEST_COMMAND} -R newhdrgen_integration_test | ||
) | ||
|
||
message(STATUS "Integration test for newhdrgen added.") | ||
endif() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
//===-- C standard library header test_small-------------------------------===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef LLVM_LIBC_TEST_SMALL_H | ||
#define LLVM_LIBC_TEST_SMALL_H | ||
|
||
#include "__llvm-libc-common.h" | ||
#include "llvm-libc-macros/test_small-macros.h" | ||
|
||
#define MACRO_A 1 | ||
|
||
#define MACRO_B 2 | ||
|
||
#include <llvm-libc-types/type_a.h> | ||
#include <llvm-libc-types/type_b.h> | ||
|
||
enum { | ||
enum_a = value_1, | ||
enum_b = value_2, | ||
}; | ||
|
||
__BEGIN_C_DECLS | ||
|
||
#ifdef FUNC_A_16 | ||
void func_a()CONST_FUNC_A; | ||
#endif // FUNC_A_16 | ||
|
||
#ifdef FUNC_B_16 | ||
int func_b(int, float)CONST_FUNC_B; | ||
#endif // FUNC_B_16 | ||
|
||
extern obj object_1; | ||
extern obj object_2; | ||
|
||
__END_C_DECLS | ||
|
||
#endif // LLVM_LIBC_TEST_SMALL_H |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
//===-- C standard library header test_small-------------------------------===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef LLVM_LIBC_TEST_SMALL_H | ||
#define LLVM_LIBC_TEST_SMALL_H | ||
|
||
#include "__llvm-libc-common.h" | ||
#include "llvm-libc-macros/test_small-macros.h" | ||
|
||
%%public_api() | ||
|
||
#endif // LLVM_LIBC_TEST_SMALL_H |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
header: test_header.h | ||
macros: | ||
- macro_name: MACRO_A | ||
macro_value: 1 | ||
- macro_name: MACRO_B | ||
macro_value: 2 | ||
types: | ||
- type_name: type_a | ||
- type_name: type_b | ||
enums: | ||
- name: enum_a | ||
value: value_1 | ||
- name: enum_b | ||
value: value_2 | ||
objects: | ||
- object_name: object_1 | ||
object_type: obj | ||
- object_name: object_2 | ||
object_type: obj | ||
functions: | ||
- name: func_a | ||
return_type: void | ||
arguments: [] | ||
standards: | ||
- stdc | ||
guard: FUNC_A_16 | ||
attributes: CONST_FUNC_A | ||
- name: func_b | ||
return_type: int | ||
arguments: | ||
- type: int | ||
- type: float | ||
standards: | ||
- stdc | ||
guard: FUNC_B_16 | ||
attributes: CONST_FUNC_B |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
//===-- C standard library header test_small-------------------------------===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef LLVM_LIBC_TEST_SMALL_H | ||
#define LLVM_LIBC_TEST_SMALL_H | ||
|
||
#include "__llvm-libc-common.h" | ||
#include "llvm-libc-macros/test_small-macros.h" | ||
|
||
#define MACRO_A 1 | ||
|
||
#define MACRO_B 2 | ||
|
||
#include <llvm-libc-types/type_a.h> | ||
#include <llvm-libc-types/type_b.h> | ||
|
||
enum { | ||
enum_a = value_1, | ||
enum_b = value_2, | ||
}; | ||
|
||
__BEGIN_C_DECLS | ||
|
||
#ifdef FUNC_A_16 | ||
void func_a()CONST_FUNC_A; | ||
#endif // FUNC_A_16 | ||
|
||
#ifdef FUNC_B_16 | ||
int func_b(int, float)CONST_FUNC_B; | ||
#endif // FUNC_B_16 | ||
|
||
extern obj object_1; | ||
extern obj object_2; | ||
|
||
__END_C_DECLS | ||
|
||
#endif // LLVM_LIBC_TEST_SMALL_H |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import subprocess | ||
import unittest | ||
from pathlib import Path | ||
import os | ||
import argparse | ||
|
||
|
||
class TestHeaderGenIntegration(unittest.TestCase): | ||
def setUp(self): | ||
parser = argparse.ArgumentParser( | ||
description="TestHeaderGenIntegration arguments" | ||
) | ||
parser.add_argument( | ||
"--output_dir", type=str, help="Output directory for generated headers" | ||
) | ||
args, _ = parser.parse_known_args() | ||
output_dir_env = os.getenv("TEST_OUTPUT_DIR") | ||
|
||
self.output_dir = Path( | ||
args.output_dir | ||
if args.output_dir | ||
else output_dir_env if output_dir_env else "libc/newhdrgen/tests/output" | ||
) | ||
|
||
self.maxDiff = None | ||
# Adjust based on your directory structure such as being in build etc. | ||
self.source_dir = Path(__file__).resolve().parent.parent.parent.parent | ||
|
||
def run_script(self, yaml_file, h_def_file, output_dir): | ||
yaml_file = self.source_dir / yaml_file | ||
h_def_file = self.source_dir / h_def_file | ||
result = subprocess.run( | ||
[ | ||
"python3", | ||
str(self.source_dir / "libc/newhdrgen/yaml_to_classes.py"), | ||
str(yaml_file), | ||
str(h_def_file), | ||
"--output_dir", | ||
str(output_dir), | ||
], | ||
capture_output=True, | ||
text=True, | ||
) | ||
|
||
print("STDOUT:", result.stdout) | ||
print("STDERR:", result.stderr) | ||
result.check_returncode() | ||
|
||
def compare_files(self, generated_file, expected_file): | ||
with generated_file.open("r") as gen_file: | ||
gen_content = gen_file.read() | ||
with expected_file.open("r") as exp_file: | ||
exp_content = exp_file.read() | ||
|
||
self.assertEqual(gen_content, exp_content) | ||
|
||
def test_generate_header(self): | ||
yaml_file = "libc/newhdrgen/tests/input/test_small.yaml" | ||
h_def_file = "libc/newhdrgen/tests/input/test_small.h.def" | ||
expected_output_file = ( | ||
self.source_dir / "libc/newhdrgen/tests/expected_output/test_header.h" | ||
) | ||
output_file = self.output_dir / "test_small.h" | ||
|
||
if not self.output_dir.exists(): | ||
self.output_dir.mkdir(parents=True) | ||
|
||
self.run_script(yaml_file, h_def_file, self.output_dir) | ||
|
||
self.compare_files(output_file, expected_output_file) | ||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.