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

feat(be): implement special judge on iris #2234

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
Open
2 changes: 2 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ RUN architecture=$(dpkg --print-architecture) && if [ "$architecture" = "arm64"
fi
RUN chmod 750 /app/sandbox/libjudger.so

RUN curl -L "https://github.com/MikeMirzayanov/testlib/raw/refs/heads/master/testlib.h" -o "/usr/include/testlib.h"

# Install dependencies
RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
&& apt-get -y install --no-install-recommends netcat direnv
Expand Down
2 changes: 1 addition & 1 deletion .env.development
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,4 @@ TEST_DATABASE_URL=postgresql://postgres:[email protected]:5434/skkuding?schema=publ


# TODO: Add information where each of these variables are used
# TODO: I want to edit values after the container is created...
# TODO: I want to edit values after the container is created...
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
### Code-Server ###
code-server/git.sh
code-server/.env.development


### Node ###
# Logs
logs
Expand Down
3 changes: 3 additions & 0 deletions apps/iris/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/skkuding/codedang/apps/iris/src/service/file"
"github.com/skkuding/codedang/apps/iris/src/service/logger"
"github.com/skkuding/codedang/apps/iris/src/service/sandbox"
"github.com/skkuding/codedang/apps/iris/src/service/specialScript"
"github.com/skkuding/codedang/apps/iris/src/service/testcase"
"github.com/skkuding/codedang/apps/iris/src/utils"
"go.opentelemetry.io/otel"
Expand Down Expand Up @@ -56,6 +57,7 @@ func main() {

database := postgres.NewPostgresDataSource(ctx)
testcaseManager := testcase.NewTestcaseManager(database)
specialScriptManager := specialScript.NewSpecialScriptManager(database)

fileManager := file.NewFileManager("/app/sandbox/results")
langConfig := sandbox.NewLangConfig(fileManager, "/app/sandbox/policy/java_policy")
Expand All @@ -68,6 +70,7 @@ func main() {
compiler,
runner,
testcaseManager,
specialScriptManager,
langConfig,
fileManager,
logProvider,
Expand Down
13 changes: 13 additions & 0 deletions apps/iris/src/common/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,16 @@ const (
EXCHANGE = "judger-exchange"
RESULT_KEY = "result"
)

type ExecType uint

const (
T_Judge ExecType = iota
T_Run
T_SpecialJudge
T_SpecialRun
)

// To be changed
const MAX_SPECIAL_MEMORY = 256 * 1024 * 1024
const MAX_SPECIAL_TIME = 10000
2 changes: 1 addition & 1 deletion apps/iris/src/connector/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func Factory(c Module, p Providers, args ...any) Connector {
if err != nil {
panic(err)
}

return rabbitmq.NewConnector(consumer, producer, p.Router, p.Logger)
case HTTP:

Expand Down
1 change: 1 addition & 0 deletions apps/iris/src/connector/rabbitmq/connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ func (c *connector) Disconnect() {}
func (c *connector) handle(message amqp.Delivery, ctx context.Context) {

resultChan := make(chan []byte)

if message.Type == "" {
resultChan <- router.NewResponse("", nil, fmt.Errorf("type(message property) must not be empty")).Marshal()
close(resultChan)
Expand Down
3 changes: 3 additions & 0 deletions apps/iris/src/handler/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,14 @@ var (
ErrValidate = errors.New("validation error")
ErrSandbox = errors.New("sandbox error")
ErrTestcaseGet = errors.New("testcase get error")
ErrSpecialScriptGet = errors.New("specialScript get error")
ErrCompile = errors.New("compile error")
ErrWrongAnswer = errors.New("wrong answer")
ErrCpuTimeLimitExceed = errors.New("cputime limit exceeded")
ErrRealTimeLimitExceed = errors.New("realtime limit exceeded")
ErrMemoryLimitExceed = errors.New("memory limit exceeded")
ErrRuntime = errors.New("runtime error")
ErrSegFault = errors.New("segmentation fault")
ErrSpecialPE = errors.New("segmentation fault")
ErrSpecialFail = errors.New("segmentation fault")
)
13 changes: 13 additions & 0 deletions apps/iris/src/handler/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,19 @@ type Handler interface {
// error mapper? (han)
}

func SpecialExitCodeToJudgeResultCode(code int) JudgeResultCode {
switch code {
case sandbox.SPECIAL_WA:
return WRONG_ANSWER
case sandbox.SPECAIL_PE:
return SPECIAL_PE
case sandbox.SPECIAL_FAIL:
return SYSTEM_ERROR
}

return ACCEPTED
}

// FIXME: use more proper name
// FIXME: refactor
func SandboxResultCodeToJudgeResultCode(code sandbox.ResultCode) JudgeResultCode {
Expand Down
Loading
Loading