Skip to content
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

[libc] integration test outputs header in build #98385

Merged
merged 2 commits into from
Jul 11, 2024

Conversation

aaryanshukla
Copy link
Contributor

  • python's unittest does not allow for custom args so sys.argv was used

- python's unittest does not allow for custom args so sys.argv was used
@llvmbot llvmbot added the libc label Jul 10, 2024
@llvmbot
Copy link
Collaborator

llvmbot commented Jul 10, 2024

@llvm/pr-subscribers-libc

Author: None (aaryanshukla)

Changes
  • python's unittest does not allow for custom args so sys.argv was used

Full diff: https://github.com/llvm/llvm-project/pull/98385.diff

3 Files Affected:

  • (modified) libc/newhdrgen/CMakeLists.txt (+3-3)
  • (removed) libc/newhdrgen/tests/output/test_small.h (-42)
  • (modified) libc/newhdrgen/tests/test_integration.py (+13-10)
diff --git a/libc/newhdrgen/CMakeLists.txt b/libc/newhdrgen/CMakeLists.txt
index 33750d181c4b3..9b14d91ea510f 100644
--- a/libc/newhdrgen/CMakeLists.txt
+++ b/libc/newhdrgen/CMakeLists.txt
@@ -1,16 +1,16 @@
 if(LLVM_LIBC_FULL_BUILD)
-
   enable_testing()
 
   set(NEWHDGEN_TESTS_DIR ${CMAKE_CURRENT_SOURCE_DIR}/tests)
+  set(TEST_OUTPUT_DIR ${CMAKE_CURRENT_BINARY_DIR}/newhdrgen/output)
 
   add_test(
     NAME newhdrgen_integration_test
-    COMMAND ${CMAKE_COMMAND} -E env PYTHONPATH=${CMAKE_CURRENT_SOURCE_DIR} python3 ${NEWHDGEN_TESTS_DIR}/test_integration.py
+    COMMAND python3 ${NEWHDGEN_TESTS_DIR}/test_integration.py --output_dir ${TEST_OUTPUT_DIR}
   )
   
   add_custom_target(check-newhdrgen
-    COMMAND ${CMAKE_CTEST_COMMAND} -R newhdrgen_integration_test
+    COMMAND ${CMAKE_CTEST_COMMAND} -R newhdrgen_integration_test --output-on-failure
   )
 
   message(STATUS "Integration test for newhdrgen added.")
diff --git a/libc/newhdrgen/tests/output/test_small.h b/libc/newhdrgen/tests/output/test_small.h
deleted file mode 100644
index d6ae0d0e282e7..0000000000000
--- a/libc/newhdrgen/tests/output/test_small.h
+++ /dev/null
@@ -1,42 +0,0 @@
-//===-- 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
diff --git a/libc/newhdrgen/tests/test_integration.py b/libc/newhdrgen/tests/test_integration.py
index 59d8d4204a578..1b88e1cc6db72 100644
--- a/libc/newhdrgen/tests/test_integration.py
+++ b/libc/newhdrgen/tests/test_integration.py
@@ -3,23 +3,15 @@
 from pathlib import Path
 import os
 import argparse
+import sys
 
 
 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"
+            output_dir_env if output_dir_env else "libc/newhdrgen/tests/output"
         )
 
         self.maxDiff = None
@@ -71,4 +63,15 @@ def test_generate_header(self):
 
 
 if __name__ == "__main__":
+    parser = argparse.ArgumentParser(description="TestHeaderGenIntegration arguments")
+    parser.add_argument(
+        "--output_dir", type=str, help="Output directory for generated headers"
+    )
+    args, remaining_argv = parser.parse_known_args()
+
+    if args.output_dir:
+        os.environ["TEST_OUTPUT_DIR"] = args.output_dir
+
+    sys.argv[1:] = remaining_argv
+
     unittest.main()

Copy link
Contributor

@michaelrj-google michaelrj-google left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@aaryanshukla aaryanshukla merged commit 05b7b22 into llvm:main Jul 11, 2024
6 checks passed
aaryanshukla added a commit to aaryanshukla/llvm-project that referenced this pull request Jul 14, 2024
- python's unittest does not allow for custom args so sys.argv was used
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants