Loading...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 | ## # Copyright (c) 2025 Apple Inc. All rights reserved. # # @APPLE_OSREFERENCE_LICENSE_HEADER_START@ # # This file contains Original Code and/or Modifications of Original Code # as defined in and that are subject to the Apple Public Source License # Version 2.0 (the 'License'). You may not use this file except in # compliance with the License. The rights granted to you under the License # may not be used to create, or enable the creation or redistribution of, # unlawful or unlicensed copies of an Apple operating system, or to # circumvent, violate, or enable the circumvention or violation of, any # terms of an Apple operating system software license agreement. # # Please obtain a copy of the License at # http://www.opensource.apple.com/apsl/ and read it before using this file. # # The Original Code and all software distributed under the License are # distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER # EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, # INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. # Please see the License for the specific language governing rights and # limitations under the License. # # @APPLE_OSREFERENCE_LICENSE_HEADER_END@ ## """Build utilities for LLDB macro tests.""" import subprocess import os from constants import XNU_ROOT, DEFAULT_SDKROOT, UNIT_TESTS_DIR, MACROS_TESTING_DIR def build_unit_test(exe_name: str): """Build a unit test executable using make. Args: exe_name: Name of the executable to build (e.g., "test_memory_macros") Raises: RuntimeError: If the build fails """ # Change to XNU root directory for the build original_cwd = os.getcwd() try: os.chdir(XNU_ROOT) # Construct the full target name with macros_testing prefix target_name = f"{MACROS_TESTING_DIR}/{exe_name}" # Run the make command cmd = [ "make", "-C", UNIT_TESTS_DIR, f"SDKROOT={DEFAULT_SDKROOT}", target_name ] print(f"Building unit test: {' '.join(cmd)}") result = subprocess.run( cmd, capture_output=True, text=True, check=False ) if result.returncode != 0: error_msg = f"Build failed for {exe_name}\n" error_msg += f"Command: {' '.join(cmd)}\n" error_msg += f"Return code: {result.returncode}\n" error_msg += f"STDOUT: {result.stdout}\n" error_msg += f"STDERR: {result.stderr}" raise RuntimeError(error_msg) print(f"Successfully built {exe_name}") if result.stdout: print(f"Build output: {result.stdout}") finally: # Always restore the original working directory os.chdir(original_cwd) def discover_unit_tests(): """Discover all unit test C files in the macros_testing directory. Returns: list: List of executable names (without .c extension) that can be built """ macros_testing_path = XNU_ROOT / "tests" / "unit" / "macros_testing" if not macros_testing_path.exists(): print(f"Warning: macros_testing directory not found at {macros_testing_path}") return [] # Find all .c files in the macros_testing directory c_files = list(macros_testing_path.glob("*.c")) # Extract executable names (remove .c extension) exe_names = [c_file.stem for c_file in c_files] print(f"Discovered {len(exe_names)} unit test(s): {exe_names}") return exe_names def build_all_unit_tests(): """Build all discovered unit test executables. Returns: dict: Dictionary with exe_name as key and success status as value """ exe_names = discover_unit_tests() if not exe_names: print("No unit tests found to build") return {} print(f"Building {len(exe_names)} unit test executable(s)...") results = {} failed_builds = [] for exe_name in exe_names: try: print(f"\n--- Building {exe_name} ---") build_unit_test(exe_name) results[exe_name] = True print(f"✓ Successfully built {exe_name}") except RuntimeError as e: results[exe_name] = False failed_builds.append(exe_name) print(f"✗ Failed to build {exe_name}: {e}") # Summary successful_builds = [name for name, success in results.items() if success] print("\n=== Build Summary ===") print(f"Total: {len(exe_names)}") print(f"Successful: {len(successful_builds)}") print(f"Failed: {len(failed_builds)}") if successful_builds: print(f"✓ Built: {', '.join(successful_builds)}") if failed_builds: print(f"✗ Failed: {', '.join(failed_builds)}") # Don't raise an exception here - let tests run with available executables print("Warning: Some builds failed, but continuing with available executables") return results |