blob: 245430cba9561557069e12d10360272ddc713aea [file] [log] [blame]
Patrick Georgi5ac6a632020-10-28 17:29:38 +01001#!/bin/sh
2set -e
3
Nico Huber819ba502023-03-07 22:59:01 +00004TEMP_DIR=$(mktemp -d)
5trap "rm -rf ${TEMP_DIR}" EXIT
6
Nico Huber4eb97482024-04-21 21:44:33 +02007dd bs=$((128*1024)) count=1 </dev/urandom >"${TEMP_DIR}/rand"
8dd bs=$((128*1024)) count=1 </dev/urandom >"${TEMP_DIR}/rand2"
9dd bs=$((128*1024)) count=1 </dev/zero | tr '\000' '\377' >"${TEMP_DIR}/empty"
Nico Huber819ba502023-03-07 22:59:01 +000010
Nico Huber4eb97482024-04-21 21:44:33 +020011test_prog() {
12 prog="$1"
Nico Huber819ba502023-03-07 22:59:01 +000013
Nico Huber4eb97482024-04-21 21:44:33 +020014 "${prog}" -p dummy:emulate=M25P10.RES,image="${TEMP_DIR}/image" -w "${TEMP_DIR}/rand"
15 "${prog}" -p dummy:emulate=M25P10.RES,image="${TEMP_DIR}/image" -r "${TEMP_DIR}/bak"
16 cmp "${TEMP_DIR}/rand" "${TEMP_DIR}/bak"
Nico Huber7a480312023-04-10 14:54:22 +020017
Nico Huber4eb97482024-04-21 21:44:33 +020018 "${prog}" -p dummy:emulate=M25P10.RES,image="${TEMP_DIR}/image" -c M25P10 -w "${TEMP_DIR}/rand2"
19 "${prog}" -p dummy:emulate=M25P10.RES,image="${TEMP_DIR}/image" -c M25P10 -v "${TEMP_DIR}/rand2"
20
21 "${prog}" -p dummy:emulate=M25P10.RES,image="${TEMP_DIR}/image" -c M25P10 -E
22 "${prog}" -p dummy:emulate=M25P10.RES,image="${TEMP_DIR}/image" -c M25P10 -v "${TEMP_DIR}/empty"
23}
24
Nico Huber3d2f2122024-04-21 21:54:15 +020025if [ "${MAKECMD=make}" ]; then
26 ${MAKECMD} clean
27 eval ${MAKECMD} -j${CPUS:-$(nproc)} CC="\"${CC:-ccache cc}\"" ${MAKEARGS-CONFIG_EVERYTHING=yes}
28 test_prog ./flashprog
29fi
Nico Huber4eb97482024-04-21 21:44:33 +020030
Nico Huber3d2f2122024-04-21 21:54:15 +020031if [ "${MESONCMD=meson}" ]; then
32 eval ${MESONCMD} setup ${MESONARGS--D programmer=all --buildtype release} "${TEMP_DIR}/build"
33 ninja ${CPUS:+-j${CPUS}} -C "${TEMP_DIR}/build"
34 test_prog "${TEMP_DIR}/build/flashprog"
35fi