File: test_integration.py

package info (click to toggle)
llvm-toolchain-19 1%3A19.1.7-10.1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,999,140 kB
  • sloc: cpp: 6,951,711; ansic: 1,486,157; asm: 913,598; python: 232,024; f90: 80,126; objc: 75,281; lisp: 37,276; pascal: 16,990; sh: 10,033; ml: 5,058; perl: 4,724; awk: 3,523; makefile: 3,252; javascript: 2,504; xml: 892; fortran: 664; cs: 573
file content (81 lines) | stat: -rw-r--r-- 2,520 bytes parent folder | download | duplicates (6)
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
import subprocess
import unittest
from pathlib import Path
import os
import argparse
import sys


class TestHeaderGenIntegration(unittest.TestCase):
    def setUp(self):
        self.output_dir = Path(
            args.output_dir if args.output_dir else "libc/newhdrgen/tests/output"
        )

        self.maxDiff = None

        self.source_dir = Path(__file__).resolve().parent.parent.parent.parent

    def run_script(self, yaml_file, h_def_file, output_dir, entry_points):
        yaml_file = self.source_dir / yaml_file
        h_def_file = self.source_dir / h_def_file
        command = [
            "python3",
            str(self.source_dir / "libc/newhdrgen/yaml_to_classes.py"),
            str(yaml_file),
            "--h_def_file",
            str(h_def_file),
            "--output_dir",
            str(output_dir),
        ]

        for entry_point in entry_points:
            command.extend(["--e", entry_point])

        result = subprocess.run(
            command,
            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"
        entry_points = {"func_b", "func_a", "func_c", "func_d", "func_e"}

        if not self.output_dir.exists():
            self.output_dir.mkdir(parents=True)

        self.run_script(yaml_file, h_def_file, self.output_dir, entry_points)

        self.compare_files(output_file, expected_output_file)


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()

    TestHeaderGenIntegration.output_dir = args.output_dir

    sys.argv[1:] = remaining_argv

    unittest.main()