Evaluating LLM Code Generation with a UEFI Shell Snake Game Benchmark

    Leaderboard scores show how a model performs on standard question sets, but they do not show whether it can complete a development task with clear deliverables in a specific technical environment. This article describes a benchmark built on a real development task: a snake game for UEFI Shell. It covers the runtime environment, test protocol, scoring table, defect classification, and model selection process. The scope is limited to this UEFI Shell game benchmark and does not cover web or backend scenarios.

    1. Scope and Evaluation Metrics

    Standard question sets usually consist of function-level problems with clear inputs and outputs, and their scoring is easy to automate. These problems suit measuring basic coding ability, but engineering work differs in three ways. Engineering tasks require understanding requirements across multiple files, designing data structures, and handling edge cases. Real development also relies on knowledge that is not in any documentation, such as platform conventions and hardware behavior. Deliverables must also compile, run, and be maintainable. Passing unit tests does not make a program usable.

    The evaluation therefore needs to check two things: whether the model can write the code, and whether that code can be delivered. This article defines four metrics:

    • Task completion: how many requirement items the final program satisfies.
    • First-attempt success rate: the share of sessions in which the first output builds and starts normally.
    • Repair efficiency: how many rounds the model needs, using compiler or runtime error feedback, to reach a usable state.
    • Code quality: whether resources are allocated and freed in pairs, whether error return values are checked, and whether loops avoid busy waiting.

    The boundaries also need to be stated. Results only reflect the tested task, the tested model version, and the tested prompt. They cannot be extended to other scenarios.

    2. Benchmark Task: UEFI Shell Snake Game

    UEFI Shell is the benchmark environment for two reasons. First, requirements and acceptance criteria can be written as explicit items. Second, the runtime is controlled. The model cannot rely on the file system, process management, or C standard library that an operating system would provide.

    UEFI is the interface specification for modern computer firmware. Shell is its pre-boot command environment. Programs running there can only use services the firmware provides, such as text output, key reading, timed waits, and memory allocation. EDK II provides libraries such as BaseLib, UefiLib, and MemoryAllocationLib, but it has no standard functions such as printf or rand. The model must find alternatives. For example, randomness can come from EFI_RNG_PROTOCOL or from time services, depending on what the firmware supports.

    2.1 Runtime Environment Checklist

    Before testing, record each of the following items in the test report:

    • Host machine: operating system and kernel version, CPU architecture.
    • Compiler: GCC version, and the EDK II toolchain tag (for example, GCC5).
    • EDK II: repository URL and commit hash, or release tag.
    • Firmware: an OVMF X64 image built from that EDK II version, with the build command recorded.
    • Virtual machine: QEMU version and complete boot parameters.
    • Debug output: program logs collected through OVMF’s debugcon port.
    • Input injection: the QEMU monitor sendkey command, used to simulate key presses.

    2.2 Build and Run Steps

    The model must deliver a complete project, including source files, .inf files, and .dsc files. When the program allocates or frees memory, it must log each operation through DEBUG output so the results can be checked later. The build command is fixed:

    1. source edksetup.sh
    2. build -a X64 -t GCC5 -p GameSnakePkg/GameSnakePkg.dsc

    The build output is an .efi file. Place it in a directory, then mount that directory in QEMU with -drive format=raw,file=fat:rw:esp. After entering UEFI Shell, run map to find the disk number, then run fsX:\GameSnake.efi, where X is that disk number.

    Before each QEMU launch, copy OVMF_VARS from a clean source file so that variables from a previous test do not affect the results.

    Run all tests in a virtual machine only. Do not flash generated firmware or programs to real hardware, because doing so could damage the device.

    2.3 Requirement Checklist

    The model receives the full requirement text, which includes these feature items:

    1. After startup, display the title and control instructions.
    2. The snake’s initial length and position match the requirements.
    3. Arrow keys control the snake’s direction.
    4. The game ends when the snake hits a boundary.
    5. The game ends when the snake hits its own body.
    6. The snake grows after eating food.
    7. Food appears at random positions and never on the snake’s body.
    8. The screen shows the current score.
    9. Pressing ESC exits the program.
    10. After the game ends, the player can restart the game or exit correctly.

    Each feature item corresponds to one acceptance script or one manual check step.

    2.4 Code Skeleton Example

    The skeleton below shows only the basic structure of the entry point and input handling. It is not a complete program and will not build on its own. In actual testing, give the model the full requirement text and let it generate all the code.

    1. EFI_STATUS
    2. EFIAPI
    3. UefiMain(
    4. IN EFI_HANDLE ImageHandle,
    5. IN EFI_SYSTEM_TABLE *SystemTable
    6. )
    7. {
    8. EFI_INPUT_KEY Key;
    9. EFI_STATUS Status;
    10. SystemTable->ConOut->ClearScreen(SystemTable->ConOut);
    11. SystemTable->ConOut->OutputString(SystemTable->ConOut,
    12. L"Press ESC to exit\r\n");
    13. while (TRUE) {
    14. Status = SystemTable->ConIn->ReadKeyStroke(SystemTable->ConIn, &Key);
    15. if (Status == EFI_NOT_READY) {
    16. SystemTable->BootServices->Stall(16000); // About 16 milliseconds
    17. continue;
    18. }
    19. if (Key.ScanCode == SCAN_ESC) {
    20. break;
    21. }
    22. // Handle game logic here
    23. }
    24. return EFI_SUCCESS;
    25. }

    The skeleton has two easy-to-miss details. First, ReadKeyStroke returns EFI_NOT_READY when no key is pressed. It does not block. Second, if the loop has no delay, the program keeps the processor fully busy. Whether a model handles both points correctly is a useful signal of its engineering understanding.

    3. Test Protocol and Record Template

    The test protocol is fixed so that models can be compared:

    • Prompt: the first round provides only the full requirement text and the build command. No extra prompt tuning is allowed.
    • Repair rounds: after each failed build or run, send only the raw error log back to the model. Allow up to 5 rounds.
    • Sessions: run at least 5 independent sessions per model. Sessions do not share context.
    • Records: log each session with the following template.
    1. Model name:
    2. Model version or release date:
    3. Access method and interface:
    4. Temperature (record if the interface allows adjustment):
    5. Maximum output length:
    6. Prompt version (text hash):
    7. Session number and start time:
    8. Build result for each round:
    9. Run result for each round:
    10. Score breakdown:
    11. Manual review conclusion:

    4. Scoring Table and Weights

    The total score is 100 points across seven dimensions:

    Dimension Weight Scoring Criteria
    Build and startup 10 A build with no errors earns 5 points. Warnings do not deduct points, but their count must be recorded. Starting successfully in Shell and displaying the title earns 5 points.
    Functional completeness 30 10 feature items, 3 points each, scored by acceptance results.
    Input handling 15 Inject 200 arrow key presses. The debug log records each key the program processes. Key drop rate = (injected count minus processed count) divided by injected count. Below 1%: 15 points. 1% to 3%: 10 points. 3% to 10%: 5 points. Above 10%: 0 points.
    Stability 15 Run for 30 minutes with random key injection and no operator input. No crashes and no hangs earn 15 points. Each crash or hang deducts 5 points, down to zero. A hang means the screen shows no update for more than 5 seconds.
    Code quality 10 Paired memory allocation and freeing: 3 points. Return values of key functions checked: 3 points. Loops include waits and avoid busy waiting: 2 points. No obvious hazards, such as out-of-bounds writes: 2 points.
    Repair efficiency 10 Usable in round 1: 10 points. Round 2: 7 points. Round 3: 4 points. Rounds 4 to 5: 2 points. Never usable: 0 points.
    First-attempt success rate 10 The share of the 5 sessions in which the first round builds and starts successfully, multiplied by 10.

    “Usable” means the program builds and starts, and its functional completeness score is at least 15 points.

    A session that scores at least 70 points and meets the usable condition counts as a pass. For each model, report both the median score and the lowest score.

    5. Defect Classification

    In addition to scoring, record the defects that appear in each session. Classify defects as follows:

    Category Typical Example How to Identify Severity
    Build and startup Using printf, rand, or other C standard library functions. The .inf file does not declare required libraries. Compile or link errors in the build log Severe
    Input handling Blocking or busy-waiting when ReadKeyStroke returns EFI_NOT_READY. Keys overwritten. Key drop rate test. Observe processor usage. Severe (when the key drop rate exceeds 10%)
    Memory AllocatePool called without FreePool. Memory accessed after it is freed. Check whether allocation and free counts match in the debug log. Use static analysis tools. Severe
    Compatibility Hardcoded screen size that exceeds the console’s actual mode. SetMode return value not checked. Switch the console mode and run again Moderate
    Maintainability All logic placed in UefiMain. Magic numbers without names. Manual review checklist Minor

    Sessions with severe defects can earn at most 5 points