V4.1.1 A Complete C Test

EasyImplement20 minap_soc v1.5 · firmware · serverReview the topic

Write a whole C test that lives through every stage. It starts up, hands over to the bench, checks, and reports in a form the regression can read. The bench plants errors in some runs, and your test must name them.

Hardware context: One C test on ap_soc v1.5, from compile and back-door load to the pass word. A C test that names the first bad word of a region the bench changed.

Write a C test for the SRAM of ap_soc, the way a chip regression runs one. The test fills 64 words at 0x8000_8000 with known values, then hands over to the bench. The bench may change words by the back door. Then it hands back, and the test checks every word.

The hand-over uses the mailbox. Write 0x51 to TB_EVENT when the words are filled, then wait until TB_ARG holds 0x52. Word i must read 0xC0DE_0000 + i × 0x101.

Print sram: fill before the fill. If every word holds its value, print sram: ok and return 0. At the first bad word i, print sram: bad, a space, i, a space and the word as read. Then end the test with fail code i + 1. Both numbers are eight hex digits (tb_put_hex), and every line ends with a new line.

Full specification
StepFirmwareBench
1Print sram: fill; write the 64 wordswaits for TB_EVENT = 0x51
2TB_EVENT = 0x51, then wait for TB_ARG = 0x52may change words of SRAM by the back door, then TB_ARG = 0x52
3Read the 64 words back; reportends the test on the pass or fail word

The region is 0x8000_8000 to 0x8000_80FF. Your program and its stack are elsewhere in SRAM. tb_wait_event(id) returns when TB_ARG equals id. Returning a nonzero code from main writes the fail word 0xBAD0_0000 + code.

Given Files

Read-only files supplied by the bench.

tb.h
#ifndef AP_TB_H
#define AP_TB_H
_Noreturn void tb_pass(void);
_Noreturn void tb_fail(unsigned code);
void tb_putc(char byte);
void tb_puts(const char *text);
void tb_put_hex(unsigned value);
void tb_event(unsigned id);
/* Slot zero is the single bench-to-firmware argument word. */
unsigned tb_arg(unsigned n);
void tb_wait_event(unsigned id);
#endif

hal.h
#ifndef AP_HAL_H
#define AP_HAL_H
#include "ap_soc_regs.h"

/* V13.4 supplies these two functions through DPI in a host-native build. */
#ifdef AP_HOST_DPI
unsigned reg_read32(unsigned address);
void reg_write32(unsigned address, unsigned value);
#else
static inline unsigned reg_read32(unsigned address)
{
    return *(volatile unsigned *)address;
}
static inline void reg_write32(unsigned address, unsigned value)
{
    *(volatile unsigned *)address = value;
}
#endif

#define FIELD_GET(field, word) (((word) & field##_MASK) >> field##_SHIFT)
#define FIELD_PREP(field, value) (((unsigned)(value) << field##_SHIFT) & field##_MASK)
#endif

Examples

Example 1

Nothing Changed
Input
the bench changes nothing
Output
console: "sram: fill", "sram: ok"; pass

Every word holds its value, so the test returns 0 and the kit writes the pass word.

Example 2

Word 10 Cleared
Input
the bench clears word 10
Output
console: "sram: bad 0000000a 00000000"; TB_STATUS = 0xBAD0_000B

Word 10 is the first bad word, so the fail code is 10 + 1 = 0x0B.

Example 3

The Last Word
Input
the bench changes the last word, 63
Output
console: "sram: bad 0000003f 12345678"; TB_STATUS = 0xBAD0_0040

Word 63 is checked too: the loop must cover the whole region.

Constraints and Contract

  • C firmware with the kit, SRAM layout.
  • Keep the line format exactly: the bench compares the console text and the status word.
  • The bench changes words only between your event and its reply. In some runs it replies late.

Hints

Hint 1

Which kit call tells the bench you are ready, and which one waits for its answer?

Hint 2

Read each word once into a variable, and print that variable.

Hint 3

Count the codes: the first word is 0, and a fail code of 0 would mean pass.

What the grader checks: Each case runs your firmware once on the chip bench. The bench changes chosen words between your event and its reply, then compares the console text and the status word. It cannot see words you never read back.

9 checks on ap_soc v1.5 · firmware · server. Run the examples first, then check the full regression. Full checks use the server judge. Downloads contain your text only; the chip, the bench and the hidden checks stay on the server. A passing result establishes the tested cases, not a proof for all possible inputs.

See all 2 problems on this path

Report a problem with this page

Your code CSaved locally
Ln 1, Col 1Tab indents · Ctrl/⌘ + Enter runs samples
Not run yet

Nothing Changed

Input
the bench changes nothing
Expected output
console: "sram: fill", "sram: ok"; pass

Every word holds its value, so the test returns 0 and the kit writes the pass word.

Run samples executes all 3 public checks. Check all tests runs 9 checks on the server.

ap_soc v1.5 · firmware · server