Skip to content
Merged
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
14 changes: 8 additions & 6 deletions ci/test/ui-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ set -e
# stop_processes
# DISPLAY: ":99" in .gitlab-ci.yml?
# not sure if relevant
#xvfb-run tester ui

# cleanup before recording in local folder
# which is shard with normal user recordings and
Expand All @@ -25,10 +24,13 @@ set -e
# # rm -rf /tmp/codetracer
# rm -rf /dev/shm/codetracer

# pushd ui-tests;
# xvfb-run npx playwright test
# popd;
echo "========================"
# echo "RUNNING ui e2e tests"

# stop_processes
# TODO nix-shell --command "xvfb-run just test-e2e"

echo TODO

echo TODO
echo "========================"

# stop_processes
7 changes: 7 additions & 0 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -283,3 +283,10 @@ ls-trace-folder-for-id trace_id:

# end of trace folder helpers
# ===========================

# ====
# e2e helpers

test-e2e:
cd ${CODETRACER_REPO_ROOT_PATH}/ui-tests && \
env CODETRACER_OPEN_DEV_TOOLS=0 npx playwright test --reporter=list --workers=1
4 changes: 4 additions & 0 deletions nix/shells/main.nix
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@ in
mdbook
mdbook-alerts

# github CLI
gh

# cachix support
cachix

Expand Down Expand Up @@ -230,6 +233,7 @@ in

export NIX_CODETRACER_EXE_DIR=$ROOT_PATH/src/build-debug/
export LINKS_PATH_DIR=$ROOT_PATH/src/build-debug/
export CODETRACER_REPO_ROOT_PATH=$ROOT_PATH
export PATH=$PATH:$PWD/src/build-debug/bin
export PATH=$PATH:$ROOT_PATH/node_modules/.bin/
export CODETRACER_OPEN_DEV_TOOLS=1
Expand Down
3 changes: 3 additions & 0 deletions src/ct/trace/record.nim
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,9 @@ proc record*(args: seq[string]): Trace =
# registerRecordInReportFile(reportFile, trace, outputPath)
putEnv("CODETRACER_RECORDING", "")

let inUiTest = getEnv("CODETRACER_IN_UI_TEST", "") == "1"
if inUiTest:
echo fmt"> codetracer: finished with trace id: {traceId}"
return trace
except CatchableError as e:
if sessionId != -1:
Expand Down
8 changes: 6 additions & 2 deletions src/frontend/index.nim
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ proc isCtInstalled: bool


proc onClose(e: js) =
if data.config.test:
if not data.config.isNil and data.config.test:
discard
elif not close:
# TODO refactor to use just `client.send`
Expand All @@ -49,10 +49,14 @@ proc onClose(e: js) =
# --caller-pid <callerPid>
# # eventually if needed --backend-socket-host <backend-socket-host>
proc parseArgs =
# echo "parseArgs"

data.startOptions.screen = true
data.startOptions.loading = false
data.startOptions.record = false

data.startOptions.folder = electronprocess.cwd()

if electronProcess.env.hasKey(cstring"CODETRACER_TRACE_ID"):
data.startOptions.traceID = electronProcess.env[cstring"CODETRACER_TRACE_ID"].parseJSInt
data.startOptions.inTest = electronProcess.env[cstring"CODETRACER_TEST"] == cstring"1"
Expand All @@ -61,7 +65,7 @@ proc parseArgs =
else:
discard

data.startOptions.folder = electronprocess.cwd()


if electronProcess.env.hasKey(cstring"CODETRACER_TEST_STRATEGY"):
data.startOptions.rawTestStrategy = electronProcess.env[cstring"CODETRACER_TEST_STRATEGY"]
Expand Down
6 changes: 6 additions & 0 deletions ui-tests/programs/noir_example/Nargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[package]
name = "noir_example"
type = "bin"
authors = [""]

[dependencies]
2 changes: 2 additions & 0 deletions ui-tests/programs/noir_example/Prover.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
x = 0
y = 1
28 changes: 28 additions & 0 deletions ui-tests/programs/noir_example/src/main.nr
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// fn run(x: Field, y: [8; Field]) -> Field {
// let length = 8;
// for item in 0 .. length {
// let item = y[i];
// if check(x, item) {
// print("found");
// return x;
// } else {

// }
// }
// print(">");
// }
// }

fn main(x: Field, y: pub Field) {
println(f"x {x}"); // marker: PRINT_X_LINE
println(f"y {y}"); // marker: PRINT_Y_LINE
assert(x != y); // marker: ASSERT_LINE
}

// #[test]
// fn test_main() {
// main(1, 2);

// // Uncomment to make test fail
// // main(1, 1);
// }
20 changes: 20 additions & 0 deletions ui-tests/shell.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# copied and adapted from https://nix.dev/tutorials/first-steps/declarative-shell.html
# however, using unstable like flake.nix
let

nixpkgs = fetchTarball "https://github.com/NixOS/nixpkgs/tarball/nixos-unstable";

pkgs = import nixpkgs { config = {}; overlays = []; };

in


pkgs.mkShellNoCC {

packages = with pkgs; [

xvfb-run

];

}
80 changes: 50 additions & 30 deletions ui-tests/tests/lib/ct_helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import * as path from "node:path";
import * as childProcess from "node:child_process";
import * as process from "node:process";
import * as fs from "node:fs";

import { test, type Page } from "@playwright/test";
import { _electron, chromium } from "playwright";
Expand Down Expand Up @@ -49,44 +48,49 @@ export function debugCodetracer(name: string, langExtension: string): void {
}

export function getTestProgramNameFromPath(filePath: string): string {
const relativePath = path.relative("programs", filePath);
if (filePath.startsWith("noir_")) {
return path.basename(filePath);
} else {
const relativePath = path.relative("programs", filePath);

// Split the relative path into segments
const pathSegments = relativePath.split(path.sep);
// Split the relative path into segments
const pathSegments = relativePath.split(path.sep);

// The first segment is the folder inside 'programs'
// eslint-disable-next-line @typescript-eslint/no-magic-numbers
const folderName = pathSegments[0];
return folderName;
// The first segment is the folder inside 'programs'
// eslint-disable-next-line @typescript-eslint/no-magic-numbers
const folderName = pathSegments[0];
return folderName;
}
}

export function codeTracerRun(relativeSourceFilePath: string): void {
export function ctRun(relativeSourcePath: string): void {
test.beforeAll(async () => {
setupLdLibraryPath();

const sourceFilePath = path.join(testProgramsPath, relativeSourceFilePath);
const sourceFileName = path.basename(
relativeSourceFilePath,
path.extname(relativeSourceFilePath),
);
const sourcePath = path.join(testProgramsPath, relativeSourcePath);
// const sourceFileName = path.basename(
// relativeSourceFilePath,
// path.extname(relativeSourceFilePath),
// );
// const sourceFileExtension = path.extname(sourceFilePath);
const programName = getTestProgramNameFromPath(sourceFilePath);
const programName = getTestProgramNameFromPath(relativeSourcePath);

fs.mkdirSync(testBinariesPath, { recursive: true });
// fs.mkdirSync(testBinariesPath, { recursive: true });

const binaryFileName = `${programName}__${sourceFileName}`;
const binaryFilePath = path.join(testBinariesPath, binaryFileName);
// const binaryFileName = `${programName}__${sourceFileName}`;
// const binaryFilePath = path.join(testBinariesPath, binaryFileName);

buildTestProgram(sourceFilePath, binaryFilePath);
// TODO: if rr-backend?
// buildTestProgram(sourceFilePath, binaryFilePath);

const traceId = recordTestProgram(binaryFilePath);
const traceId = recordTestProgram(sourcePath);

const inBrowser = process.env.CODETRACER_TEST_IN_BROWSER === "1";
if (!inBrowser) {
const runPid = 1;
await replayCodetracerInElectron(binaryFileName, traceId, runPid);
await replayCodetracerInElectron(programName, traceId, runPid);
} else {
await replayCodetracerInBrowser(binaryFileName, traceId);
await replayCodetracerInBrowser(programName, traceId);
}
});
}
Expand Down Expand Up @@ -120,19 +124,23 @@ function setupLdLibraryPath(): void {
}

async function replayCodetracerInElectron(
binaryFileName: string,
programName: string,
traceId: number,
runPid: number,
): Promise<number> {
// not clear, but maybe possible to directly augment the playwright test report?
// test.info().annotations.push({type: 'something', description: `# starting codetracer for ${pattern}`});
console.log(`# replay codetracer rr/gdb core process for ${binaryFileName}`);
console.log(`# replay codetracer rr/gdb core process for ${programName}`);

const ctProcess = childProcess.spawn(
codetracerPath,
["start_core", binaryFileName, runPid.toString()],
["start_core", `${traceId}`, runPid.toString()],
{ cwd: codetracerInstallDir },
);
// ctProcess.stdout.setEncoding("utf8");
// ctProcess.stdout.on("data", console.log);
// ctProcess.stderr.setEncoding("utf8");
// ctProcess.stderr.on("data", console.log);
ctProcess.on("close", (code) => {
console.log(`child process exited with code ${code}`);

Expand All @@ -148,11 +156,14 @@ async function replayCodetracerInElectron(
process.env.CODETRACER_TRACE_ID = traceId.toString();
process.env.CODETRACER_IN_UI_TEST = "1";

// console.log(ctProcess);

electronApp = await electron.launch({
executablePath: electronPath,
cwd: codetracerInstallDir,
args: [indexPath],
});

const firstWindow = await electronApp.firstWindow();
const firstWindowTitle = await firstWindow.title();

Expand Down Expand Up @@ -194,7 +205,7 @@ async function replayCodetracerInBrowser(
const chromiumBrowser = await chromium.launch({
executablePath: path.join(
process.env.PLAYWRIGHT_BROWSERS_PATH,
"chromium-1091",
"chromium-1134",
"chrome-linux",
"chrome",
),
Expand Down Expand Up @@ -254,21 +265,26 @@ function buildTestProgram(
console.log(`# codetracer built ${outputBinaryPath} succesfully`);
}

function recordTestProgram(outputBinaryPath: string): number {
function recordTestProgram(recordArg: string): number {
process.env.CODETRACER_IN_UI_TEST = "1";

// non-obvious options!
// stdio: 'pipe', encoding: 'utf8' found form
// https://stackoverflow.com/a/35690273/438099
const ctProcess = childProcess.spawnSync(
codetracerPath,
["record", outputBinaryPath],
["record", recordArg],
{
cwd: codetracerInstallDir,
stdio: "pipe",
encoding: "utf-8",
},
);
// console.log(ctProcess);
if (ctProcess.error !== undefined || ctProcess.status !== OK_EXIT_CODE) {
console.log(`ERROR: codetracer record: ${ctProcess.error}`);
console.log(
`ERROR: codetracer record: error: ${ctProcess.error}; status: ${ctProcess.status}`,
);
console.log(ctProcess.stderr);
process.exit(ERROR_EXIT_CODE);
}
Expand All @@ -292,7 +308,7 @@ function recordTestProgram(outputBinaryPath: string): number {
process.exit(ERROR_EXIT_CODE);
}
console.log(
`# codetracer recorded a trace for ${outputBinaryPath} with trace id ${maybeTraceId} succesfully`,
`# codetracer recorded a trace for ${recordArg} with trace id ${maybeTraceId} succesfully`,
);
return maybeTraceId;
}
Expand Down Expand Up @@ -328,6 +344,10 @@ export async function readyOnEntryTest(): Promise<void> {
await page.locator(".location-path").click();
}

export async function loadedEventLog(): Promise<void> {
await page.locator(".data-tables-footer-rows-count").click();
}

export class CodetracerTestError extends Error {
constructor(msg: string) {
super(msg);
Expand Down
Loading