blob: 74118fb5acca33b70999900fcf7b71d16779d9fc [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 Huber72b30a02024-04-21 21:59:19 +020014 if [ "${CROSS_COMPILE}" ]; then
15 return 0
16 fi
17
Nico Huber4eb97482024-04-21 21:44:33 +020018 "${prog}" -p dummy:emulate=M25P10.RES,image="${TEMP_DIR}/image" -w "${TEMP_DIR}/rand"
19 "${prog}" -p dummy:emulate=M25P10.RES,image="${TEMP_DIR}/image" -r "${TEMP_DIR}/bak"
20 cmp "${TEMP_DIR}/rand" "${TEMP_DIR}/bak"
Nico Huber7a480312023-04-10 14:54:22 +020021
Nico Huber4eb97482024-04-21 21:44:33 +020022 "${prog}" -p dummy:emulate=M25P10.RES,image="${TEMP_DIR}/image" -c M25P10 -w "${TEMP_DIR}/rand2"
23 "${prog}" -p dummy:emulate=M25P10.RES,image="${TEMP_DIR}/image" -c M25P10 -v "${TEMP_DIR}/rand2"
24
25 "${prog}" -p dummy:emulate=M25P10.RES,image="${TEMP_DIR}/image" -c M25P10 -E
26 "${prog}" -p dummy:emulate=M25P10.RES,image="${TEMP_DIR}/image" -c M25P10 -v "${TEMP_DIR}/empty"
27}
28
Nico Huber3d2f2122024-04-21 21:54:15 +020029if [ "${MAKECMD=make}" ]; then
30 ${MAKECMD} clean
31 eval ${MAKECMD} -j${CPUS:-$(nproc)} CC="\"${CC:-ccache cc}\"" ${MAKEARGS-CONFIG_EVERYTHING=yes}
32 test_prog ./flashprog
33fi
Nico Huber4eb97482024-04-21 21:44:33 +020034
Nico Huber3d2f2122024-04-21 21:54:15 +020035if [ "${MESONCMD=meson}" ]; then
36 eval ${MESONCMD} setup ${MESONARGS--D programmer=all --buildtype release} "${TEMP_DIR}/build"
37 ninja ${CPUS:+-j${CPUS}} -C "${TEMP_DIR}/build"
38 test_prog "${TEMP_DIR}/build/flashprog"
Nico Huberc7b549e2023-03-19 14:27:43 +000039
40 if [ "${MAKECMD}" -a ! "${CROSS_COMPILE}" ]; then
41 ./flashprog -L >"${TEMP_DIR}/flashprog.supported"
42 "${TEMP_DIR}/build/flashprog" -L >"${TEMP_DIR}/mashprog.supported"
43 diff -u "${TEMP_DIR}/flashprog.supported" "${TEMP_DIR}/mashprog.supported"
44 fi
Nico Huber3d2f2122024-04-21 21:54:15 +020045fi