diff --git a/apps/backend/apps/client/src/submission/class/judger-response.dto.ts b/apps/backend/apps/client/src/submission/class/judger-response.dto.ts index 2ed8e2abf8..1c15e31fcd 100644 --- a/apps/backend/apps/client/src/submission/class/judger-response.dto.ts +++ b/apps/backend/apps/client/src/submission/class/judger-response.dto.ts @@ -20,7 +20,7 @@ class JudgeResult { } export class JudgerResponse { - @Max(8) + @Max(9) @Min(0) @IsNotEmpty() resultCode: number diff --git a/apps/backend/apps/client/src/submission/test/submission-sub.service.spec.ts b/apps/backend/apps/client/src/submission/test/submission-sub.service.spec.ts index b5d22846e8..e3059e2a7a 100644 --- a/apps/backend/apps/client/src/submission/test/submission-sub.service.spec.ts +++ b/apps/backend/apps/client/src/submission/test/submission-sub.service.spec.ts @@ -176,11 +176,13 @@ describe('SubmissionSubscriptionService', () => { ).to.be.true }) - it('should call handleJudgeError when CompileError or ServerError detected', async () => { + it('should call handleJudgeError when ServerError detected', async () => { const handlerSpy = sandbox.stub(service, 'handleJudgeError').resolves() - + const updateSpy = sandbox + .stub(service, 'updateTestcaseJudgeResult') + .resolves() const serverErrMsg = { - resultCode: 8, + resultCode: 9, submissionId: 1, error: '', judgeResult @@ -189,6 +191,25 @@ describe('SubmissionSubscriptionService', () => { await service.handleJudgerMessage(serverErrMsg) expect(handlerSpy.calledOnceWith(ResultStatus.ServerError, serverErrMsg)) .to.be.true + expect(updateSpy.notCalled).to.be.true + }) + + it('should call handleJudgeError when CompileError detected', async () => { + const handlerSpy = sandbox.stub(service, 'handleJudgeError').resolves() + const updateSpy = sandbox + .stub(service, 'updateTestcaseJudgeResult') + .resolves() + const serverErrMsg = { + resultCode: 6, + submissionId: 1, + error: '', + judgeResult + } + + await service.handleJudgerMessage(serverErrMsg) + expect(handlerSpy.calledOnceWith(ResultStatus.CompileError, serverErrMsg)) + .to.be.true + expect(updateSpy.notCalled).to.be.true }) }) diff --git a/apps/backend/libs/constants/src/submission.constants.ts b/apps/backend/libs/constants/src/submission.constants.ts index 9e1a84c319..c2d42dcfcb 100644 --- a/apps/backend/libs/constants/src/submission.constants.ts +++ b/apps/backend/libs/constants/src/submission.constants.ts @@ -39,8 +39,8 @@ export const Status = (code: number) => { return ResultStatus.CompileError case 7: // TESTCASE_ERROR return ResultStatus.ServerError - case 8: // SERVER_ERROR - return ResultStatus.ServerError + case 8: // Segmentation Fault + return ResultStatus.SegmentationFaultError default: return ResultStatus.ServerError } diff --git a/apps/backend/prisma/migrations/20240819125317_add_segmentation_fault_on_result_status_enum/migration.sql b/apps/backend/prisma/migrations/20240819125317_add_segmentation_fault_on_result_status_enum/migration.sql new file mode 100644 index 0000000000..245d83187b --- /dev/null +++ b/apps/backend/prisma/migrations/20240819125317_add_segmentation_fault_on_result_status_enum/migration.sql @@ -0,0 +1,2 @@ +-- AlterEnum +ALTER TYPE "ResultStatus" ADD VALUE 'SegmentationFaultError'; diff --git a/apps/backend/prisma/schema.prisma b/apps/backend/prisma/schema.prisma index af308ec59a..16ac1399b5 100644 --- a/apps/backend/prisma/schema.prisma +++ b/apps/backend/prisma/schema.prisma @@ -170,7 +170,7 @@ model Problem { /// "locked": boolean /// }[] /// } - + template Json[] @default([]) languages Language[] timeLimit Int @map("time_limit") // unit: MilliSeconds @@ -435,6 +435,7 @@ enum ResultStatus { MemoryLimitExceeded OutputLimitExceeded ServerError + SegmentationFaultError } model CodeDraft { diff --git a/apps/iris/src/handler/errors.go b/apps/iris/src/handler/errors.go index 932daf483e..8e42db253c 100644 --- a/apps/iris/src/handler/errors.go +++ b/apps/iris/src/handler/errors.go @@ -51,4 +51,5 @@ var ( ErrRealTimeLimitExceed = errors.New("realtime limit exceeded") ErrMemoryLimitExceed = errors.New("memory limit exceeded") ErrRuntime = errors.New("runtime error") + ErrSegFault = errors.New("segmentation fault") ) diff --git a/apps/iris/src/handler/interface.go b/apps/iris/src/handler/interface.go index 558cb75570..88cf12e964 100644 --- a/apps/iris/src/handler/interface.go +++ b/apps/iris/src/handler/interface.go @@ -33,22 +33,20 @@ func SandboxResultCodeToJudgeResultCode(code sandbox.ResultCode) JudgeResultCode func ParseError(j JudgeResult) error { if j.ResultCode != ACCEPTED { - return resultCodeToError(j.ResultCode) - } - return nil -} - -func ParseFirstError(j []JudgeResult) error { - for _, res := range j { - if res.ResultCode != ACCEPTED { - return resultCodeToError(res.ResultCode) + // TODO : Customizing Results + if j.Signal == 11 && j.ResultCode != MEMORY_LIMIT_EXCEEDED { + return resultCodeToError(SEGMENATION_FAULT) + } + if j.RealTime >= 2000 && j.Signal == 9 && j.ResultCode == RUNTIME_ERROR { + return resultCodeToError(REAL_TIME_LIMIT_EXCEEDED) } + return resultCodeToError(j.ResultCode) } return nil } func resultCodeToError(code JudgeResultCode) error { - caller := "parse first error" + caller := "parse error" err := &HandlerError{ caller: caller, level: logger.INFO, @@ -64,6 +62,8 @@ func resultCodeToError(code JudgeResultCode) error { return err.Wrap(ErrMemoryLimitExceed) case RUNTIME_ERROR: return err.Wrap(ErrRuntime) + case SEGMENATION_FAULT: + return err.Wrap(ErrSegFault) } return &HandlerError{caller: caller, err: ErrSandbox, level: logger.ERROR} } diff --git a/apps/iris/src/handler/judge-handler.go b/apps/iris/src/handler/judge-handler.go index a613895fef..e72a951b0a 100644 --- a/apps/iris/src/handler/judge-handler.go +++ b/apps/iris/src/handler/judge-handler.go @@ -106,6 +106,7 @@ const ( MEMORY_LIMIT_EXCEEDED RUNTIME_ERROR SYSTEM_ERROR + SEGMENATION_FAULT ) type JudgeHandler struct { @@ -338,7 +339,7 @@ func (j *JudgeHandler) judgeTestcase(idx int, dir string, validReq *Request, res.SetJudgeExecResult(runResult.ExecResult) if runResult.ExecResult.ResultCode != sandbox.RUN_SUCCESS { - res.SetJudgeResultCode(JudgeResultCode(runResult.ExecResult.ResultCode)) + res.SetJudgeResultCode(SandboxResultCodeToJudgeResultCode(runResult.ExecResult.ResultCode)) goto Send } diff --git a/apps/iris/src/router/response.go b/apps/iris/src/router/response.go index b74e2d7bef..53ea42697b 100644 --- a/apps/iris/src/router/response.go +++ b/apps/iris/src/router/response.go @@ -26,6 +26,7 @@ const ( RUNTIME_ERROR COMPILE_ERROR TESTCASE_ERROR + SEGMENTATION_FAULT_ERROR SERVER_ERROR ) @@ -96,5 +97,8 @@ func ErrorToResultCode(err error) ResultCode { if errors.Is(err, handler.ErrTestcaseGet) { return TESTCASE_ERROR } + if errors.Is(err, handler.ErrSegFault) { + return SEGMENTATION_FAULT_ERROR + } return SERVER_ERROR }