WIP: feat: scoreboard (#15) #31
							
								
								
									
										10
									
								
								Makefile
									
									
									
									
									
								
							
							
						
						
									
										10
									
								
								Makefile
									
									
									
									
									
								
							| 
						 | 
				
			
			@ -1,19 +1,23 @@
 | 
			
		|||
.PHONY: all clean test
 | 
			
		||||
.PHONY: all build clean prepare-test test
 | 
			
		||||
 | 
			
		||||
BUILD_DIR = ./build
 | 
			
		||||
TMP_DIR = ./tmp
 | 
			
		||||
APPS := $(notdir $(wildcard ./cmd/*))
 | 
			
		||||
FLAGS := "-s -w"
 | 
			
		||||
 | 
			
		||||
all:
 | 
			
		||||
all: build
 | 
			
		||||
 | 
			
		||||
build:
 | 
			
		||||
	$(foreach APP,$(APPS), go build -ldflags=$(FLAGS) -o $(BUILD_DIR)/$(APP) ./cmd/$(APP);)
 | 
			
		||||
 | 
			
		||||
clean:
 | 
			
		||||
	rm -rf $(BUILD_DIR)/*
 | 
			
		||||
	rm -rf $(TMP_DIR)/*
 | 
			
		||||
	rm -rf *.out
 | 
			
		||||
 | 
			
		||||
prepare-test:
 | 
			
		||||
	git submodule update --init --remote
 | 
			
		||||
 | 
			
		||||
test:
 | 
			
		||||
	./scripts/prepare_test_repos.sh
 | 
			
		||||
	./scripts/prepare_test_repos.sh $(TMP_DIR)
 | 
			
		||||
	go test -coverprofile cover.out -v ./...
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -17,7 +17,7 @@ $ go build -o ./tmp/go-judge ./cmd/go-judge
 | 
			
		|||
5. Run `go-judge`.
 | 
			
		||||
```bash
 | 
			
		||||
$ # make sure you are in go-judge directory
 | 
			
		||||
$ ./tmp/go-judge -enable-grpc -enable-debug -enable-metrics
 | 
			
		||||
$ ./tmp/go-judge -http-addr 0.0.0.0:5050 -grpc-addr 0.0.0.0:5051 -monitor-addr 0.0.0.0:5052 -enable-grpc -enable-debug -enable-metrics
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
6. Pull submodules. It might be slow, so only run it when necessary.
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -10,9 +10,11 @@ import (
 | 
			
		|||
)
 | 
			
		||||
 | 
			
		||||
type Conf struct {
 | 
			
		||||
	LogLevel   int    `default:"0"`
 | 
			
		||||
	OutputPath string `default:"joj3_result.json"`
 | 
			
		||||
	Stages     []struct {
 | 
			
		||||
	SandboxExecServer string `default:"localhost:5051"`
 | 
			
		||||
	SandboxToken      string `default:""`
 | 
			
		||||
	LogLevel          int    `default:"0"`
 | 
			
		||||
	OutputPath        string `default:"joj3_result.json"`
 | 
			
		||||
	Stages            []struct {
 | 
			
		||||
		Name     string
 | 
			
		||||
		Executor struct {
 | 
			
		||||
			Name string
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -5,7 +5,7 @@ import (
 | 
			
		|||
	"log/slog"
 | 
			
		||||
	"os"
 | 
			
		||||
 | 
			
		||||
	_ "focs.ji.sjtu.edu.cn/git/FOCS-dev/JOJ3/internal/executors"
 | 
			
		||||
	"focs.ji.sjtu.edu.cn/git/FOCS-dev/JOJ3/internal/executors"
 | 
			
		||||
	_ "focs.ji.sjtu.edu.cn/git/FOCS-dev/JOJ3/internal/parsers"
 | 
			
		||||
	"focs.ji.sjtu.edu.cn/git/FOCS-dev/JOJ3/internal/stage"
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -77,6 +77,7 @@ func main() {
 | 
			
		|||
		os.Exit(1)
 | 
			
		||||
	}
 | 
			
		||||
	setupSlog(conf)
 | 
			
		||||
	executors.InitWithConf(conf.SandboxExecServer, conf.SandboxToken)
 | 
			
		||||
	stages := generateStages(conf)
 | 
			
		||||
	defer stage.Cleanup()
 | 
			
		||||
	results := stage.Run(stages)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -66,7 +66,7 @@ func TestMain(t *testing.T) {
 | 
			
		|||
	scoreboard := scoreboard.Scoreboard{}
 | 
			
		||||
	scoreboard.Init()
 | 
			
		||||
	var tests []string
 | 
			
		||||
	root := "../../tmp/submodules/JOJ3-examples"
 | 
			
		||||
	root := "../../tmp/submodules/JOJ3-examples/examples/"
 | 
			
		||||
	err := filepath.Walk(root, func(path string, info os.FileInfo, err error) error {
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			return err
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -2,8 +2,13 @@ package executors
 | 
			
		|||
 | 
			
		||||
import (
 | 
			
		||||
	_ "focs.ji.sjtu.edu.cn/git/FOCS-dev/JOJ3/internal/executors/dummy"
 | 
			
		||||
	_ "focs.ji.sjtu.edu.cn/git/FOCS-dev/JOJ3/internal/executors/sandbox"
 | 
			
		||||
	"focs.ji.sjtu.edu.cn/git/FOCS-dev/JOJ3/internal/executors/sandbox"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
// this file does nothing but imports to ensure all the init() functions
 | 
			
		||||
// in the subpackages are called
 | 
			
		||||
 | 
			
		||||
// overwrite the default registered executors
 | 
			
		||||
func InitWithConf(sandboxExecServer, sandboxToken string) {
 | 
			
		||||
	sandbox.InitWithConf(sandboxExecServer, sandboxToken)
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,6 +1,7 @@
 | 
			
		|||
package sandbox
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"log/slog"
 | 
			
		||||
	"os"
 | 
			
		||||
	"path/filepath"
 | 
			
		||||
	"strings"
 | 
			
		||||
| 
						 | 
				
			
			@ -113,7 +114,12 @@ func convertPBFile(i stage.CmdFile) *pb.Request_File {
 | 
			
		|||
				i.Src = &absPath
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
		return &pb.Request_File{File: &pb.Request_File_Local{Local: &pb.Request_LocalFile{Src: *i.Src}}}
 | 
			
		||||
		s, err := os.ReadFile(*i.Src)
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			s = []byte{}
 | 
			
		||||
			slog.Error("read file error", "path", *i.Src, "error", err)
 | 
			
		||||
		}
 | 
			
		||||
		return &pb.Request_File{File: &pb.Request_File_Memory{Memory: &pb.Request_MemoryFile{Content: s}}}
 | 
			
		||||
	case i.Content != nil:
 | 
			
		||||
		s := strToBytes(*i.Content)
 | 
			
		||||
		return &pb.Request_File{File: &pb.Request_File_Memory{Memory: &pb.Request_MemoryFile{Content: s}}}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -18,6 +18,7 @@ type Sandbox struct {
 | 
			
		|||
func (e *Sandbox) Run(cmds []stage.Cmd) ([]stage.ExecutorResult, error) {
 | 
			
		||||
	var err error
 | 
			
		||||
	if e.execClient == nil {
 | 
			
		||||
		slog.Debug("create exec client", "server", e.execServer)
 | 
			
		||||
		e.execClient, err = createExecClient(e.execServer, e.token)
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			return nil, err
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -8,9 +8,17 @@ var name = "sandbox"
 | 
			
		|||
 | 
			
		||||
func init() {
 | 
			
		||||
	stage.RegisterExecutor(name, &Sandbox{
 | 
			
		||||
		// TODO: read from conf
 | 
			
		||||
		execServer: "localhost:5051",
 | 
			
		||||
		token:      "",
 | 
			
		||||
		cachedMap:  make(map[string]string),
 | 
			
		||||
	})
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// overwrite the default registered executor
 | 
			
		||||
func InitWithConf(execServer, token string) {
 | 
			
		||||
	stage.RegisterExecutor(name, &Sandbox{
 | 
			
		||||
		execServer: execServer,
 | 
			
		||||
		token:      token,
 | 
			
		||||
		cachedMap:  make(map[string]string),
 | 
			
		||||
	})
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -2,7 +2,7 @@
 | 
			
		|||
 | 
			
		||||
set -ex
 | 
			
		||||
declare -A repo_names
 | 
			
		||||
tmp_dir="./tmp"
 | 
			
		||||
tmp_dir=${1:-./tmp}
 | 
			
		||||
submodules_dir="$tmp_dir/submodules"
 | 
			
		||||
rm -rf $submodules_dir
 | 
			
		||||
mkdir -p $submodules_dir
 | 
			
		||||
| 
						 | 
				
			
			@ -24,6 +24,7 @@ for submodule in $submodules; do
 | 
			
		|||
    repo_names[$repo_name]=1
 | 
			
		||||
    cd $repo_dir
 | 
			
		||||
    git checkout -q $branch
 | 
			
		||||
    git reset -q --hard origin/$branch
 | 
			
		||||
    cd -
 | 
			
		||||
    submodule_dir="$submodules_dir/$repo_name/$submodule"
 | 
			
		||||
    mkdir -p $submodule_dir
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										21
									
								
								scripts/run_foreach_test_repos.sh
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										21
									
								
								scripts/run_foreach_test_repos.sh
									
									
									
									
									
										Executable file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,21 @@
 | 
			
		|||
#!/usr/bin/env bash
 | 
			
		||||
 | 
			
		||||
set -ex
 | 
			
		||||
tmp_dir=${1:-./tmp}
 | 
			
		||||
JOJ3=$(git rev-parse --show-toplevel)/build/joj3
 | 
			
		||||
command=${2:-$JOJ3}
 | 
			
		||||
submodules_dir="$tmp_dir/submodules"
 | 
			
		||||
submodules=$(git config --file .gitmodules --get-regexp path | awk '{ print $2 }')
 | 
			
		||||
for submodule in $submodules; do
 | 
			
		||||
    url=$(git config --file .gitmodules --get-regexp "submodule.$submodule.url" | awk '{ print $2 }')
 | 
			
		||||
    repo_name=$(echo $url | rev | cut -d'/' -f 1 | rev | cut -d'.' -f 1)
 | 
			
		||||
    submodule_dir="$submodules_dir/$repo_name/$submodule"
 | 
			
		||||
    cd $submodule_dir
 | 
			
		||||
    eval "$command"
 | 
			
		||||
    if [[ $command == $JOJ3 ]]; then
 | 
			
		||||
        if [ -f "./expected.json" ]; then
 | 
			
		||||
            mv -f "joj3_result.json" "expected.json"
 | 
			
		||||
        fi
 | 
			
		||||
    fi
 | 
			
		||||
    cd -
 | 
			
		||||
done
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user