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