Skip to content
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

Merge Dev #2

Merged
merged 11 commits into from
Aug 12, 2023
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
23 changes: 23 additions & 0 deletions .github/workflows/bun.sh.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Bun.sh CI

on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]

jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
bun-version: [0.7.1, 0.7.2]
steps:
- uses: actions/checkout@v3
- name: Use Bun.sh ${{ matrix.bun-version }}
uses: oven-sh/setup-bun@v1
with:
bun-version: ${{ matrix.bun-version }}
- run: bun install
- run: bun build ./src/main.ts --compile --outfile grader
# - run: bun run test # TODO: Add unit tests
15 changes: 15 additions & 0 deletions .github/workflows/docker-image.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: Docker Runner

on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Build the Docker image
run: docker build ./projects/ --tag w2wizard/runner:$(date +%s)
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ To create a new reference project, use the following command:
bun run new < project-name >
```

### Dashboard

To view the dashboard, just visit [localhost](http://localhost:8000/) in your browser.
The dashboard merely displays statistics about the grading server itself and not much else.

### 🐳 Docker Setup

> **Note**: The docker image hasn't been configured properly yet to make sure the code isn't actually doing something stupid (deleting files, cd, ...) atm it uses Kornshell just a basic simple attempt but there are no serious measures whatsoever.
Expand Down
Binary file modified bun.lockb
Binary file not shown.
11 changes: 8 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,25 @@
"description": "A code grading server",
"module": "./src/main.ts",
"scripts": {
"new": "/bin/bash ./scripts/new.sh",
"new": "/bin/bash ./scripts/new.sh",
"start": "bun run ./src/main.ts",
"build": "bun build ./src/main.ts --compile --outfile grader"
},
"directories": {
"src": "src"
},
"devDependencies": {
"bun-types": "^0.7.1"
"bun-types": "^0.7.1",
"typed-html": "^3.0.1"
},
"peerDependencies": {
"typescript": "^5.0.0"
},
"type": "module",
"dependencies": {
"@elysiajs/fn": "^0.5.2",
"@elysiajs/static": "^0.5.3",
"@elysiajs/html": "^0.5.2",
"@elysiajs/static": "^0.6.0",
"chalk": "^5.3.0",
"elysia": "^0.5.24",
"http-parser-js": "^0.5.8"
Expand Down
1 change: 0 additions & 1 deletion projects/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ WORKDIR /app
RUN apt-get update && apt-get install -y \
ksh \
git \
sudo \
cmake \
coreutils \
vim-common \
Expand Down
21 changes: 18 additions & 3 deletions projects/entry.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
#!/bin/bash
#=============================================================================

# This is a hack because otherwise docker complains about a missing
# /app/start.sh file which is because the volume isn't mounted yet
/bin/bash /app/start.sh
echo "[+] Starting..."
if [ -z "$GIT_URL" ] || [ -z "$GIT_BRANCH" ] || [ -z "$GIT_COMMIT" ]; then
echo -e "GIT_URL, GIT_BRANCH and GIT_COMMIT must be set"
exit 1
fi

# See: https://www.gnu.org/software/coreutils/manual/html_node/timeout-invocation.html#timeout-invocation
echo "[+] Timeout: $TIMEOUT seconds"
timeout --kill-after=$TIMEOUT $TIMEOUT /bin/bash /app/start.sh

exitCode=$?
if [ $exitCode -ne 0 ]; then
echo -e "[+] Failed: $exitCode"
else
echo -e "[+] Success"
fi
exit $exitCode
7 changes: 1 addition & 6 deletions projects/hello_world/start.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
#!/bin/bash
#==============================================================================
if [ -z "$GIT_URL" ] || [ -z "$GIT_BRANCH" ] || [ -z "$GIT_COMMIT" ]; then
echo -e "GIT_URL, GIT_BRANCH and GIT_COMMIT must be set"
exit 1
fi

ID=$(xxd -l 16 -ps /dev/urandom | tr -d " \n")
ProjectDIR="/tmp/$ID/project"
ObjectsDIR="/tmp/$ID/objects"
Expand All @@ -27,7 +22,7 @@ function gitCloneCommit() {
# Build the project
function build() {
echo "[+] Building ..."
timeout 25s make -C $ProjectDIR -j4
make -C $ProjectDIR -j4

# Other steps ...

Expand Down
4 changes: 4 additions & 0 deletions projects/libft/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"enabled": true,
"timeout": 20
}
61 changes: 37 additions & 24 deletions projects/libft/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
//=============================================================================

import { sleep } from "bun";
import { dlopen, FFIType, ptr } from "bun:ffi";
import { dlopen, FFIType, ptr, toArrayBuffer } from "bun:ffi";
import { describe, expect, it, beforeAll, afterAll } from "bun:test";

/**
Expand All @@ -24,6 +24,10 @@ import { describe, expect, it, beforeAll, afterAll } from "bun:test";
// TODO: Come up with a neater way to generate the type definitions?
// NOTE(W2): Convert the static library to a shared library for dlopen to work.
const { symbols, close } = dlopen("libft.so", {
ft_strdup: {
returns: FFIType.ptr,
args: [FFIType.ptr],
},
ft_strlen: {
returns: FFIType.i32,
args: [FFIType.ptr],
Expand Down Expand Up @@ -129,12 +133,27 @@ describe("makefile", () => {
const text = await makefile.text();
const requiredFlags = ["-Wall", "-Wextra", "-Werror"];

await sleep(1000);

expect(requiredFlags.every((flag) => text.includes(flag))).toBe(true);
});
});

// strdup
//=============================================================================
describe("strdup", () => {
it("duplicates a string", () => {
const sample = "Hello, world!";
const ptrSample = ptr(Buffer.from(`${sample}\0`, "utf8"));
const result = toArrayBuffer(symbols.ft_strdup(ptrSample), 0, sample.length);
const output = Buffer.from(result).toString("utf8");
expect(output).toBe(sample);
});

it("returns null if the string is empty", () => {
const emptyStr = Buffer.from(`\0`, "utf8");
expect(symbols.ft_strdup(ptr(emptyStr))).toBe(null);
});
});

// isalpha
//=============================================================================
describe("isalpha", () => {
Expand Down Expand Up @@ -241,14 +260,12 @@ describe("strlen", () => {
//=============================================================================
describe("memset", () => {
it("set characters to a value", () => {
const size = 10;
const value = 42;
const size = 42;
const value = 42; // *
const buffer = Buffer.alloc(size);
const ptrBuffer = ptr(buffer);
symbols.ft_memset(ptrBuffer, value, size);
for (const byte of buffer) {
expect(byte).toBe(value);
}

symbols.ft_memset(ptr(buffer), value, size);
buffer.forEach((byte) => expect(byte).toBe(value));
});
});

Expand All @@ -258,36 +275,32 @@ describe("bzero", () => {
it("zeroes out a buffer", () => {
const size = 10;
const buffer = Buffer.alloc(size, 42);
const ptrBuffer = ptr(buffer);
symbols.ft_bzero(ptrBuffer, size);
for (const byte of buffer) {
expect(byte).toBe(0);
}

symbols.ft_bzero(ptr(buffer), size);
buffer.forEach((byte) => expect(byte).toBe(0));
});
});

// memcpy
//=============================================================================
describe("memcpy", () => {
it("copies data from source to destination", () => {
const source = Buffer.from("Hello, world!\0", "utf8");
const source = Buffer.from("Hello, world!\0");
const destination = Buffer.alloc(source.length);
const ptrSource = ptr(source);
const ptrDestination = ptr(destination);
symbols.ft_memcpy(ptrDestination, ptrSource, source.length);

symbols.ft_memcpy(ptr(destination), ptr(source), source.length);
expect(destination.toString("utf8")).toBe(source.toString("utf8"));
});
});

// ft_memmove
//=============================================================================
describe("ft_memmove", () => {
describe("memmove", () => {
it("copies overlapping data from source to destination", () => {
const source = Buffer.from("Hello, world!\0", "utf8");
const source = Buffer.from("Hello, world!\0");
const destination = Buffer.alloc(source.length);
const ptrSource = ptr(source);
const ptrDestination = ptr(destination);
symbols.ft_memmove(ptrDestination, ptrSource, source.length);

symbols.ft_memmove(ptr(source), ptr(destination), source.length);
expect(destination.toString("utf8")).toBe(source.toString("utf8"));
});
});
Expand Down
6 changes: 1 addition & 5 deletions projects/libft/start.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
#!/bin/bash
#==============================================================================
if [ -z "$GIT_URL" ] || [ -z "$GIT_BRANCH" ] || [ -z "$GIT_COMMIT" ]; then
echo -e "GIT_URL, GIT_BRANCH and GIT_COMMIT must be set"
exit 1
fi

ID=$(xxd -l 16 -ps /dev/urandom | tr -d ' \n')
ProjectDIR="/tmp/$ID/project"
Expand All @@ -27,7 +23,7 @@ function gitCloneCommit() {
# Build the project
function build() {
echo "[+] Building ..."
timeout 25s make -C $ProjectDIR -j4
make -C $ProjectDIR -j4

rm -rf $ObjectsDIR && mkdir -p $ObjectsDIR
find $ProjectDIR -name "Makefile" -exec cp {} $Home \;
Expand Down
Loading