xref: /freebsd/crypto/libecc/scripts/crossrun.sh (revision f0865ec9906d5a18fa2a3b61381f22ce16e606ad)
1#/*
2# *  Copyright (C) 2017 - This file is part of libecc project
3# *
4# *  Authors:
5# *      Ryad BENADJILA <ryadbenadjila@gmail.com>
6# *      Arnaud EBALARD <arnaud.ebalard@ssi.gouv.fr>
7# *      Jean-Pierre FLORI <jean-pierre.flori@ssi.gouv.fr>
8# *
9# *  Contributors:
10# *      Nicolas VIVET <nicolas.vivet@ssi.gouv.fr>
11# *      Karim KHALFALLAH <karim.khalfallah@ssi.gouv.fr>
12# *
13# *  This software is licensed under a dual BSD and GPL v2 license.
14# *  See LICENSE file at the root folder of the project.
15# */
16#!/bin/sh
17
18run_triplet_wordsize(){
19	triplet=$1
20	wordsize=$2
21	echo "======== RUNNING RELEASE FOR $triplet / $wordsize"
22        if [ "$triplet" != "i386-apple-darwin" ] && [ "$triplet" != "x86_64-apple-darwin" ] && [ "$triplet" != "x86_64h-apple-darwin" ] && [ "$triplet" != "i686-w64-mingw32" ] && [ "$triplet" != "x86_64-w64-mingw32" ]; then
23		echo "  [X] Using QEMU static"
24		$CROSSBUILD_OUTPUT/"$triplet"/word"$wordsize"/ec_self_tests_"$triplet"_word"$wordsize"_static vectors
25		$CROSSBUILD_OUTPUT/"$triplet"/word"$wordsize"/ec_self_tests_"$triplet"_word"$wordsize"_debug_static vectors
26		#$CROSSBUILD_OUTPUT/"$triplet"/word"$wordsize"/ec_self_tests_"$triplet"_word"$wordsize"_static rand
27	fi
28	if [ "$triplet" = "i386-apple-darwin" ] || [ "$triplet" = "x86_64-apple-darwin" ] || [ "$triplet" = "x86_64h-apple-darwin" ]; then
29		echo "  [X] Testing MAC-OS binaries is futur work!"
30	fi
31	if [ "$triplet" = "i686-w64-mingw32" ] || [ "$triplet" = "x86_64-w64-mingw32" ]; then
32		echo "  [X] Using WINE"
33		wine $CROSSBUILD_OUTPUT/"$triplet"/word"$wordsize"/ec_self_tests_"$triplet"_word"$wordsize"_static vectors
34		wine $CROSSBUILD_OUTPUT/"$triplet"/word"$wordsize"/ec_self_tests_"$triplet"_word"$wordsize"_debug_static vectors
35		#wine $CROSSBUILD_OUTPUT/"$triplet"/word"$wordsize"/ec_self_tests_"$triplet"_word"$wordsize"_static rand
36	fi
37}
38
39
40print_help(){
41	echo "$0 uses qemu-static and wine to run self tests"
42	echo "with multiple word sizes (16, 32 and 64)."
43	echo "The produced binaries are expected to be in the 'crossbuild_out' folder."
44	echo "Supported platform triplets are:"
45	echo "arm-linux-gnueabi / arm-linux-gnueabihf / powerpc64le-linux-gnu / aarch64-linux-gnu /"
46	echo "mipsel-linux-gnu / i386-apple-darwin / x86_64-apple-darwin / i686-w64-mingw32 / x86_64-w64-mingw32."
47}
48
49
50######### Script main
51SRC_DIR=`dirname "$(readlink -f "$0")"`/..
52CROSSBUILD_OUTPUT=$SRC_DIR/scripts/crossbuild_out/
53
54# Check for the qemu-static command line
55for arch in i386 x86_64 arm ppc64 aarch64 mipsel;
56do
57	QEMU_CHECK=$(qemu-$arch-static -h)
58	if [ $? -ne 0 ]; then
59		echo "qemu-$arch-static is not installed ... Please install it! (usually in qemu-user-static)"
60		exit
61	fi
62done
63
64WINE_CHECK=$(wine --help)
65if [ $? -ne 0 ]; then
66	echo "wine is not installed ... Please install it!"
67	exit
68fi
69
70WINE64_CHECK=$(wine64 --help)
71if [ $? -ne 0 ]; then
72	echo "wine64 is not installed ... Please install it!"
73	exit
74fi
75
76# Print help if asked
77if [ "$1" = "-h" ]
78then
79	print_help $0
80	exit
81fi
82
83# If we have arguments, just execute subcommand
84if [ "$1" = "-triplet" ]
85then
86	# If no specific word size has been given, do all the sizes
87	if [ "$3" = "" ]
88	then
89		for wordsize in 16 32 64;
90		do
91			run_triplet_wordsize $2 $wordsize
92		done
93	else
94		run_triplet_wordsize $2 $3
95	fi
96	exit
97fi
98
99ALL_CHECKS=""
100for wordsize in 16 32 64;
101do
102	for triplet in arm-linux-gnueabi arm-linux-gnueabihf powerpc64le-linux-gnu aarch64-linux-gnu mipsel-linux-gnu i386-apple-darwin x86_64-apple-darwin x86_64h-apple-darwin i686-w64-mingw32 x86_64-w64-mingw32;
103	do
104		ALL_CHECKS="$ALL_CHECKS\n-triplet $triplet $wordsize"
105	done
106done
107
108if [ "$1" = "-cpu" ]
109then
110	if [ "$3" = "-triplet" ]
111	then
112		echo "-cpu and -triplet are not compatible ..."
113		exit
114	else
115		# User defined number of CPUs
116		NCPU=$2
117	fi
118else
119	# Get number of CPUs for parallel processing
120	NCPU=`getconf _NPROCESSORS_ONLN`
121fi
122echo "Parallelizing on $NCPU processors"
123# Unleash the kraken
124echo $ALL_CHECKS | xargs -n 4 -P $NCPU sh `readlink -f "$0"`
125