V4.2.2 The Test That Cannot Fail

MediumFix25 minap_soc v1.5 · firmware · serverReview the topic

A test reports pass on every run, even when the bench sends it garbage. Its checks are right; the way it tells the bench is not. Repair the reporting so that every failure ends the test with its own code.

Hardware context: The mailbox of ap_soc v1.5: TB_STATUS, TB_PUTC, TB_EVENT and TB_ARG in ap_sysctl, seen by the bench's passive monitor. Repairing a test that could never fail.

This test of the UART receive path asks the bench for a greeting and checks its two bytes. Then it asks for a reply word and checks that it came. Here are two runs: the right greeting, and the greeting "Hi" with a capital H.

Both runs end with TB_STATUS = 0x900D. The bench reads only the status word.
the bench sends "hi":  pass, console "checks done"
the bench sends "Hi":  pass, console "checks done"

The checks are right. Repair how the test reports, so that the bench can tell every outcome apart. The first failed check ends the test with its code. Code 1 is a wrong first byte, 2 a wrong second byte. Code 3 is a missing reply, 4 a missing byte. A run with no failure prints checks done and passes.

Full specification
TB_STATUS wordWhat the bench does
2main entered: the test really started
0x900DPass: the test ends here
0xBAD0_0000 + codeFail with a 16-bit code: the test ends here
Any later wordNothing: the first pass or fail word is the end

A byte or the reply counts as missing after 4,000 polls. The bench sends each byte after TB_EVENT 0x60 and the reply word 0x62 into TB_ARG after TB_EVENT 0x61. In some runs it sends fewer bytes, or none.

Run the examples with Capture waves on. The Timeline then shows 256 cycles from cycle 170. It shows each completed write to TB_STATUS (tb_status_write), the core's data bus and the receive pad IO1. Watch where the first status word falls against the greeting on IO1.

Given Files

Read-only files supplied by the bench.

drivers/uart.h
#ifndef AP_UART_H
#define AP_UART_H
#include "hal.h"

static inline void uart_flush(void)
{
    while (!FIELD_GET(UART0_STATUS_ROOM, reg_read32(UART0_STATUS))) { }
}

static inline void uart_putc(unsigned char byte)
{
    uart_flush();
    reg_write32(UART0_TXDATA, byte);
}

static inline unsigned char uart_getc(void)
{
    while (!FIELD_GET(UART0_STATUS_RX_READY, reg_read32(UART0_STATUS))) { }
    return reg_read32(UART0_RXDATA);
}

static inline void uart_enable_rx_irq(void)
{
    reg_write32(UART0_IRQ_ENABLE, UART0_IRQ_ENABLE_RX_READY_MASK);
}
#endif

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

mailbox.h
#ifndef AP_MAILBOX_H
#define AP_MAILBOX_H
#include "ap_soc_regs.h"
#define AP_MAILBOX_BASE SYSCTL_TB_STATUS
#define TB_ROM_ENTERED 1
#define TB_MAIN_ENTERED 2
#define TB_PASS_WORD 0x900d
#define TB_FAIL_BASE 0xbad00000
#endif

UART0 · register manual
OffsetRegisterBitsFieldAccessResetHeld byMeaning
0x000TXDATA7:0datawonot storedThe low byte is the next byte to send. Byte to send.
0x004STATUS0roomroblockTransmit room and receive queue state. The transmitter can take a byte.
0x004STATUS1rx_readyroblockAt least one received byte waits.
0x004STATUS2rx_fullroblockThe receive queue is full.
0x008IRQ_ENABLE0roomrw0x0regsWhich status bits raise interrupt source 1. ROOM raises the request.
0x008IRQ_ENABLE1rx_readyrw0x0regsRX_READY raises the request (new in v1.5).
0x00CRXDATA7:0dataroblockThe oldest received byte. The read removes it from the queue. Received byte.
0x010DIV15:0cyclesrw0x0010regsBit time in clk_sys cycles (new in v1.5). clk_sys cycles a bit.

Examples

Example 1

The Right Greeting
Input
the bench sends "hi" and replies
Output
console: "checks done"; TB_STATUS = 0x900D

Both bytes and the reply arrive, so no check fails.

Example 2

A Capital H
Input
the first byte is H
Output
TB_STATUS = 0xBAD0_0001

Check 1 fails first, and its failure ends the test.

Example 3

No Reply
Input
the bench never replies
Output
TB_STATUS = 0xBAD0_0003

The reply never comes; after 4,000 polls check 3 fails.

Constraints and Contract

  • C firmware with the kit, SRAM layout.
  • Keep the checks, their order and the event numbers.
  • Each failure must end the test with its own fail code; a pass prints checks done.

Hints

Hint 1

Look at the first thing main does. What does the bench do with that word?

Hint 2

What does uart_getc do when no byte ever comes?

Hint 3

Which kit call ends a test with a fail code from inside a helper function?

What the grader checks: Each case runs the test once with the bench sending a chosen greeting and reply. It compares the status word, and the console on a pass. The bench cannot see how the test reached its word, only which word came first.

8 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

The Right Greeting

Input
the bench sends "hi" and replies
Expected output
console: "checks done"; TB_STATUS = 0x900D

Both bytes and the reply arrive, so no check fails.

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

ap_soc v1.5 · firmware · server