1#!/bin/bash
2
3# Must be run from the project's root directory.
4
5# checks if a certain packet has been dead-code-eliminated from the resulting binary.
6# Arg 1: example to build
7# Arg 2: packet name
8
9if [ -z "$1" ]; then
10    echo "Must pass example name as first argument (e.g: armv4t)"
11    exit 1
12fi
13
14if [ -z "$2" ]; then
15    echo "Must pass packet name as second argument (e.g: qRcmd)"
16    exit 1
17fi
18
19cargo build --release --example $1 --features="std __dead_code_marker"
20strip ./target/release/examples/$1
21
22output=$(strings ./target/release/examples/$1 | sort | grep --color=always "<$2,")
23
24if [[ $output ]]; then
25    echo $output
26    echo "Dead code NOT eliminated!"
27    exit 1
28else
29    echo "Dead code eliminated."
30    exit 0
31fi
32