Skip to content

Commit

Permalink
Update test files regarding to dump and run spidermonkey on android
Browse files Browse the repository at this point in the history
Signed-off-by: Seonghyun Kim <[email protected]>
  • Loading branch information
ksh8281 authored and clover2123 committed May 19, 2023
1 parent 0285779 commit 9581488
Show file tree
Hide file tree
Showing 5 changed files with 254 additions and 142 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/es-actions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ jobs:
dpkg -X libicu-dev_70.1-2ubuntu1_i386.deb $GITHUB_WORKSPACE/icu32
- name: Build x86
env:
BUILD_OPTIONS: -DESCARGOT_HOST=linux -DESCARGOT_ARCH=x86 -DESCARGOT_MODE=release -DESCARGOT_LIBICU_SUPPORT_WITH_DLOPEN=OFF -DESCARGOT_OUTPUT=shell_test -GNinja
BUILD_OPTIONS: -DESCARGOT_HOST=linux -DESCARGOT_ARCH=x86 -DESCARGOT_MODE=release -DESCARGOT_THREADING=ON -DESCARGOT_LIBICU_SUPPORT_WITH_DLOPEN=OFF -DESCARGOT_OUTPUT=shell_test -GNinja
run: |
export CXXFLAGS="-I$GITHUB_WORKSPACE/icu32/usr/include"
export LDFLAGS="-L$GITHUB_WORKSPACE/icu32/usr/lib/i386-linux-gnu -Wl,-rpath=$GITHUB_WORKSPACE/icu32/usr/lib/i386-linux-gnu"
Expand Down
53 changes: 48 additions & 5 deletions tools/run-tests.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3

# Copyright 2018-present Samsung Electronics Co., Ltd.
#
Expand Down Expand Up @@ -281,13 +281,12 @@ def run_test262_dump(engine, arch):

@runner('test262-dump-run', default=False)
def run_test262_dump_run(engine, arch):
run(['g++', "./tools/test/test262/test-data-runner.cpp", "-o", "./test/test262/test-data-runner", "-g3", "-std=c++11", "-lpthread"],
run(['g++', "./tools/test/test-data-runner/test-data-runner.cpp", "-o", "./tools/test/test-data-runner/test-data-runner", "-g3", "-std=c++11", "-lpthread"],
cwd=PROJECT_SOURCE_DIR,
stdout=PIPE)

import multiprocessing
cc = multiprocessing.cpu_count()
stdout = run(['./test-data-runner', engine, str(cc), "1"],
stdout = run([PROJECT_SOURCE_DIR + '/tools/test/test-data-runner/test-data-runner', "--shell", engine,
"--test", "test262", "--test-data", join(PROJECT_SOURCE_DIR, 'test', 'test262', 'test262_data')],
cwd=join(PROJECT_SOURCE_DIR, 'test', 'test262'),
stdout=PIPE)

Expand Down Expand Up @@ -328,6 +327,50 @@ def run_spidermonkey(engine, arch):
print(diffline)
raise Exception('failure files differ')

@runner('spidermonkey-dump', default=True)
def run_spidermonkey_dump(engine, arch):
SPIDERMONKEY_OVERRIDE_DIR = join(PROJECT_SOURCE_DIR, 'tools', 'test', 'spidermonkey')
SPIDERMONKEY_DIR = join(PROJECT_SOURCE_DIR, 'test', 'vendortest', 'SpiderMonkey')

log_path = join(SPIDERMONKEY_OVERRIDE_DIR, '%s.log.txt' % arch)
if not os.path.exists(log_path):
run_spidermonkey(engine, arch)

log = sorted(readfile(log_path))
for idx, x in enumerate(log):
text = log[idx]
text = text.replace(engine + " ", "")
text = text.replace(PROJECT_SOURCE_DIR + "/", "")
text = text.replace("-f ", "")
text = text.replace("\n", "")
log[idx] = text

with open(join(SPIDERMONKEY_OVERRIDE_DIR, '%s.data.txt' % arch), "w") as output:
for idx, x in enumerate(log):
output.write(log[idx] + "\n")
if log[idx].endswith("-n.js"):
output.write("3\n")
else:
output.write("0\n")

@runner('spidermonkey-dump-run', default=True)
def run_spidermonkey_dump_run(engine, arch):
run(['g++', "./tools/test/test-data-runner/test-data-runner.cpp", "-o", "./tools/test/test-data-runner/test-data-runner", "-g3", "-std=c++11", "-lpthread"],
cwd=PROJECT_SOURCE_DIR,
stdout=PIPE)

SPIDERMONKEY_OVERRIDE_DIR = join(PROJECT_SOURCE_DIR, 'tools', 'test', 'spidermonkey')
stdout = run(['./tools/test/test-data-runner/test-data-runner', '--test-data', join(SPIDERMONKEY_OVERRIDE_DIR, '%s.data.txt' % arch),
"--shell", engine, "--env", "LOCALE=en_US"],
cwd=PROJECT_SOURCE_DIR,
stdout=PIPE)

stdout = stdout.decode("utf-8")
if stdout.find("Passed") < 0:
raise Exception('failed')
print(stdout)
print('spidermonkey-dump-passed')


@runner('jsc-stress', default=True)
def run_jsc_stress(engine, arch):
Expand Down
3 changes: 3 additions & 0 deletions tools/test/spidermonkey/excludelist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ non262/TypedArray/sort-negative-nan.js
non262/Intl/PluralRules/call.js
non262/Intl/Collator/toStringTag.js

# needs spidermonkey only test functions
non262/extensions/sharedtypedarray.js

# TODO
non262/Array/unscopables.js
non262/arrow-functions/arrow-not-as-end-of-statement.js
Expand Down
202 changes: 202 additions & 0 deletions tools/test/test-data-runner/test-data-runner.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,202 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <string>
#include <atomic>
#include <vector>
#include <thread>
#include <algorithm>

struct TestData {
std::string canBlockIsFalse;
std::string isModule;
std::string fullPath;
std::string driverFile;
std::string testFile;
std::string code;
};

enum TestKind {
General,
Test262
};

std::string g_inputPath;
std::vector<TestData> g_testDatas;
std::atomic<int> g_index;
std::atomic<int> g_passCount;
std::atomic<int> g_skipCount;
std::string g_skipPattern;
std::string g_env;
TestKind g_testKind;

int main(int argc, char* argv[])
{
std::string shellPath = "escargot";
int numThread = std::thread::hardware_concurrency();
g_inputPath = "";
g_testKind = TestKind::General;

for (int i = 1; i < argc; i++) {
if (strlen(argv[i]) >= 2 && argv[i][0] == '-') { // parse command line option
if (argv[i][1] == '-') { // `--option` case
if (strcmp(argv[i], "--shell") == 0) {
if (argc > i) {
shellPath = argv[++i];
continue;
}
} else if (strcmp(argv[i], "--test-data") == 0) {
if (argc > i) {
g_inputPath = argv[++i];
continue;
}
} else if (strcmp(argv[i], "--test") == 0) {
if (argc > i) {
std::string kind = argv[++i];
if (kind == "test262") {
g_testKind = TestKind::Test262;
}
continue;
}
} else if (strcmp(argv[i], "--threads") == 0) {
if (argc > i) {
numThread = std::stoi(argv[++i]);
continue;
}
}else if (strcmp(argv[i], "--env") == 0) {
if (argc > i) {
g_env = argv[++i];
continue;
}
}
} else { // `-option` case
}
fprintf(stderr, "Cannot recognize option `%s`", argv[i]);
continue;
}
}

if (g_inputPath == "") {
puts("please specifiy test data option with --test-data <path>");
return -1;
}

if (g_testKind == TestKind::Test262) {
g_env = "TZ=US/Pacific " + g_env;
}

int caseNum = 0;
if (g_testKind == TestKind::Test262) {
std::ifstream input(g_inputPath + "/data");

std::string canBlockIsFalse;
std::string isModule;
std::string fullPath;
std::string driverFile;
std::string testFile;
std::string code;

while (std::getline(input, canBlockIsFalse)) {
std::getline(input, isModule);
std::getline(input, fullPath);
std::getline(input, driverFile);
std::getline(input, testFile);
std::getline(input, code);

g_testDatas.push_back({
canBlockIsFalse,
isModule,
fullPath,
driverFile,
testFile,
code
});
caseNum++;
}
} else {
std::ifstream input(g_inputPath);

std::string commandLine;
std::string code;
while (std::getline(input, commandLine)) {
std::getline(input, code);
g_testDatas.push_back({
"",
"",
"",
"",
commandLine,
code
});
caseNum++;
}
}

printf("Total case number %d\n", caseNum);

std::vector<std::pair<int, int>> threadData;
std::vector<std::thread> threads;
int threadSize = caseNum / numThread;

int d = 0;
for (int i = 0; i < numThread; i ++) {
threadData.push_back(std::make_pair(
d, d + threadSize
));
d += threadSize;
}

threadData.back().second = caseNum;

for (int i = 0; i < numThread; i ++) {
threads.push_back(std::thread([](std::pair<int, int> data, std::string shellPath) {
for (int j = data.first; j < data.second; j ++) {
std::string commandline = g_env + " " + shellPath;
const auto& data = g_testDatas[j];

if (g_skipPattern.size() && data.fullPath.find(g_skipPattern) != std::string::npos) {
g_skipCount++;
printf("SKIP [%d] %s\n", g_index++, data.fullPath.data());
continue;
}

commandline += " " + data.driverFile;
if (data.canBlockIsFalse.size()) {
commandline += " --canblock-is-false";
}

if (data.isModule.size()) {
commandline += " --module";
commandline += " --filename-as=" + g_inputPath + data.fullPath;
}

commandline += " " + data.testFile;

int result = WEXITSTATUS(std::system(commandline.data()));

if (data.code == std::to_string(result)) {
g_passCount++;
printf("Success [%d] %s => %d\n", g_index++, data.fullPath.data(), result);
} else {
printf("Fail [%d] %s,%s\n", g_index++, data.fullPath.data(), commandline.data());
}
}
}, threadData[i], shellPath));
}

for (int i = 0; i < numThread; i ++) {
threads[i].join();
}

printf("Result -> %d/%d(Skipped %d) : ", ((int)g_passCount + (int)g_skipCount), caseNum, (int)g_skipCount);
if ((g_passCount + g_skipCount) == caseNum) {
puts("Passed");
} else {
puts("Failed");
}

return 0;
}
Loading

0 comments on commit 9581488

Please sign in to comment.