Skip to content

Add flexibility for testing from multiple directories #2

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
quickjs
build
build
7 changes: 7 additions & 0 deletions run_benchmarks.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/sh
set -e
cmake --build build
./build/run_sunspider_like kraken-1.0/
./build/run_sunspider_like kraken-1.1/
./build/run_sunspider_like sunspider-1.0/
./build/run_octane
87 changes: 65 additions & 22 deletions run_octane.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,22 @@
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#ifdef NO_INCLUDE_DIR
#include "quickjs.h"
#include "quickjs-libc.h"
#else
#include "quickjs/quickjs.h"
#include "quickjs/quickjs-libc.h"
#endif

void Execute(JSContext *ctx, const char *path, const char *filename, int eval_flags) {
char pathname[1024];

snprintf(pathname, sizeof pathname, "%s%s", path, filename);
filename = pathname;

void Execute(JSContext *ctx, const char *filename, int eval_flags) {
FILE *file = fopen(filename, "r");
/* assumes max test script size */
static char buf[8 << 20]; // 8 MB
Expand Down Expand Up @@ -73,34 +84,66 @@ void Execute(JSContext *ctx, const char *filename, int eval_flags) {
int main(int argc, char **argv) {
JSRuntime *rt = JS_NewRuntime();
JSContext *ctx = JS_NewContext(rt);
const char *path = "";
int argnum = 1;

/* system modules */
js_init_module_std(ctx, "std");
/* disable stack limit */
JS_SetMaxStackSize(rt, 0);

Execute(ctx, "octane/base.js", JS_EVAL_TYPE_GLOBAL);
Execute(ctx, "octane/richards.js", JS_EVAL_TYPE_GLOBAL);
Execute(ctx, "octane/deltablue.js", JS_EVAL_TYPE_GLOBAL);
Execute(ctx, "octane/crypto.js", JS_EVAL_TYPE_GLOBAL);
Execute(ctx, "octane/raytrace.js", JS_EVAL_TYPE_GLOBAL);
Execute(ctx, "octane/earley-boyer.js", JS_EVAL_TYPE_GLOBAL);
Execute(ctx, "octane/regexp.js", JS_EVAL_TYPE_GLOBAL);
Execute(ctx, "octane/splay.js", JS_EVAL_TYPE_GLOBAL);
Execute(ctx, "octane/navier-stokes.js", JS_EVAL_TYPE_GLOBAL);
Execute(ctx, "octane/pdfjs.js", JS_EVAL_TYPE_GLOBAL);
Execute(ctx, "octane/mandreel.js", JS_EVAL_TYPE_GLOBAL);
Execute(ctx, "octane/gbemu-part1.js", JS_EVAL_TYPE_GLOBAL);
Execute(ctx, "octane/gbemu-part2.js", JS_EVAL_TYPE_GLOBAL);
Execute(ctx, "octane/code-load.js", JS_EVAL_TYPE_GLOBAL);
Execute(ctx, "octane/box2d.js", JS_EVAL_TYPE_GLOBAL);
Execute(ctx, "octane/zlib.js", JS_EVAL_TYPE_GLOBAL);
Execute(ctx, "octane/zlib-data.js", JS_EVAL_TYPE_GLOBAL);
Execute(ctx, "octane/typescript.js", JS_EVAL_TYPE_GLOBAL);
Execute(ctx, "octane/typescript-input.js", JS_EVAL_TYPE_GLOBAL);
Execute(ctx, "octane/typescript-compiler.js", JS_EVAL_TYPE_GLOBAL);
if (argc > 1) {
size_t len = strlen(argv[1]);
if (len == 0 || argv[1][len - 1] == '/') {
path = argv[1];
argnum = 2;
}
}

Execute(ctx, path, "octane/base.js", JS_EVAL_TYPE_GLOBAL);

static const char *testfile[] = {
"octane/richards.js",
"octane/deltablue.js",
"octane/crypto.js",
"octane/raytrace.js",
"octane/earley-boyer.js",
"octane/regexp.js",
"octane/splay.js",
"octane/navier-stokes.js",
"octane/pdfjs.js",
"octane/mandreel.js",
"octane/gbemu-part1.js",
"octane/gbemu-part2.js",
"octane/code-load.js",
"octane/box2d.js",
"octane/zlib.js",
"octane/zlib-data.js",
"octane/typescript.js",
"octane/typescript-input.js",
"octane/typescript-compiler.js",
};
int testfile_number = sizeof(testfile) / sizeof(testfile[0]);

for (int test = 0; test < testfile_number; test++) {
const char *filename = testfile[test];
if (argc > argnum) {
int found = 0;
for (int i = argnum; i < argc; i++) {
if (strstr(filename, argv[i])) {
found = 1;
break;
}
}
if (!found) {
printf("Skipping %s%s\n", path, filename);
continue;
}
}
Execute(ctx, path, filename, JS_EVAL_TYPE_GLOBAL);
}

Execute(ctx, "run_octane.js", JS_EVAL_TYPE_MODULE);
Execute(ctx, path, "run_octane.js", JS_EVAL_TYPE_MODULE);

JS_FreeContext(ctx);

Expand Down
2 changes: 1 addition & 1 deletion run_octane.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ function PrintError(name, error) {

function PrintScore(score) {
printf("----\n");
printf("Score (version " + BenchmarkSuite.version + "): " + score);
printf("Score (version " + BenchmarkSuite.version + "): " + score + "\n");
}

BenchmarkSuite.RunSuites({
Expand Down
4 changes: 4 additions & 0 deletions run_sunspider_like.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@
#include <string.h>
#include <time.h>

#ifdef NO_INCLUDE_DIR
#include "quickjs.h"
#else
#include "quickjs/quickjs.h"
#endif

double total = 0;

Expand Down