Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #9830 from skylersaleh/m1-unit-tests
Apple M1: Add support for running unit tests on universal builds
  • Loading branch information
leoetlino committed Jun 23, 2021
2 parents a632a6a + 1203c23 commit cf26846
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 5 deletions.
39 changes: 38 additions & 1 deletion BuildMacOSUniversalBinary.py
Expand Up @@ -70,6 +70,8 @@
"generator": "Unix Makefiles",
"build_type": "Release",

"run_unit_tests": False,

}

# Architectures to build for. This is explicity left out of the command line
Expand Down Expand Up @@ -114,6 +116,9 @@ def parse_args(conf=DEFAULT_CONFIG):
help="Path to .entitlements file for code signing",
default=conf["entitlements"])

parser.add_argument("--run_unit_tests", action="store_true",
default=conf["run_unit_tests"])

parser.add_argument(
"--codesign",
help="Code signing identity to use to sign the applications",
Expand Down Expand Up @@ -323,8 +328,40 @@ def build(config):
"--verbose=2",
path])

print("Built Universal Binary successfully!")

# Build and run unit tests for each architecture
unit_test_results = {}
if config["run_unit_tests"]:
for arch in ARCHITECTURES:
if not os.path.exists(arch):
os.mkdir(arch)

print("Building and running unit tests for: {arch}")
unit_test_results[arch] = \
subprocess.call(["cmake", "--build", ".",
"--config", config["build_type"],
"--target", "unittests",
"--parallel", f"{threads}"], cwd=arch)

passed_unit_tests = True
for a in unit_test_results:
code = unit_test_results[a]
passed = code == 0

status_string = "PASSED"
if not passed:
passed_unit_tests = False
status_string = f"FAILED ({code})"

print(a + " Unit Tests: " + status_string)

if not passed_unit_tests:
exit(-1)

print("Passed all unit tests")


if __name__ == "__main__":
conf = parse_args()
build(conf)
print("Built Universal Binary successfully!")
Expand Up @@ -33,6 +33,8 @@ class TestConversion : private JitArm64
public:
TestConversion()
{
const Common::ScopedJITPageWriteAndNoExecute enable_jit_page_writes;

AllocCodeSpace(4096);
AddChildCodeSpace(&farcode, 2048);

Expand Down
2 changes: 2 additions & 0 deletions Source/UnitTests/Core/PowerPC/JitArm64/FPRF.cpp
Expand Up @@ -26,6 +26,8 @@ class TestFPRF : public JitArm64
public:
TestFPRF()
{
const Common::ScopedJITPageWriteAndNoExecute enable_jit_page_writes;

AllocCodeSpace(4096);

const u8* raw_fprf_single = GetCodePtr();
Expand Down
2 changes: 2 additions & 0 deletions Source/UnitTests/Core/PowerPC/JitArm64/Fres.cpp
Expand Up @@ -24,6 +24,8 @@ class TestFres : public JitArm64
public:
TestFres()
{
const Common::ScopedJITPageWriteAndNoExecute enable_jit_page_writes;

AllocCodeSpace(4096);

const u8* raw_fres = GetCodePtr();
Expand Down
2 changes: 2 additions & 0 deletions Source/UnitTests/Core/PowerPC/JitArm64/Frsqrte.cpp
Expand Up @@ -24,6 +24,8 @@ class TestFrsqrte : public JitArm64
public:
TestFrsqrte()
{
const Common::ScopedJITPageWriteAndNoExecute enable_jit_page_writes;

AllocCodeSpace(4096);

const u8* raw_frsqrte = GetCodePtr();
Expand Down
14 changes: 10 additions & 4 deletions Source/UnitTests/Core/PowerPC/JitArm64/MovI2R.cpp
Expand Up @@ -26,8 +26,11 @@ class TestMovI2R : public ARM64CodeBlock
ResetCodePtr();

const u8* fn = GetCodePtr();
MOVI2R(ARM64Reg::W0, value);
RET();
{
const Common::ScopedJITPageWriteAndNoExecute enable_jit_page_writes;
MOVI2R(ARM64Reg::W0, value);
RET();
}

FlushIcacheSection(const_cast<u8*>(fn), const_cast<u8*>(GetCodePtr()));

Expand All @@ -40,8 +43,11 @@ class TestMovI2R : public ARM64CodeBlock
ResetCodePtr();

const u8* fn = GetCodePtr();
MOVI2R(ARM64Reg::X0, value);
RET();
{
const Common::ScopedJITPageWriteAndNoExecute enable_jit_page_writes;
MOVI2R(ARM64Reg::X0, value);
RET();
}

FlushIcacheSection(const_cast<u8*>(fn), const_cast<u8*>(GetCodePtr()));

Expand Down

0 comments on commit cf26846

Please sign in to comment.