xref: /openbmc/openbmc/poky/scripts/test-reexec (revision c342db356d4f451821781eb24eb9f3d39d6c0c5e)
1#!/bin/bash
2
3# Test Script for task re-execution
4#
5# Copyright 2012 Intel Corporation
6#
7# SPDX-License-Identifier: GPL-2.0-or-later
8#
9# DESCRIPTION
10# This script is intended to address issues for re-execution of
11# tasks. The test results are saved in ./reexeclogs. Force build
12# logs are saved with prefix "force". Build failure logs are saved with
13# prefix "failed". Log files with prefix "initial" are used to save
14# initial build logs for each recipe. Log files with prefix "clean" are
15# used to save logs of clean task after testing for a recipe is finished.
16#
17
18targets=`bitbake -s | cut -d " " -f 1`
19
20LOGS=./reexeclogs
21
22mkdir -p $LOGS
23
24# Clear sstate files for specified recipe
25function clearsstate {
26	target=$1
27
28	sstate_dir=`bitbake $target -e | grep "^SSTATE_DIR=" | cut -d "\"" -f 2`
29	sstate_pkgspec=`bitbake $target -e | grep "^SSTATE_PKGSPEC=" | cut -d "\"" -f 2`
30	sstasks=`bitbake $target -e | grep "^SSTATETASKS=" | cut -d "\"" -f 2`
31
32	for sstask in $sstasks
33	do
34		sstask=${sstask:3}
35		case $sstask in
36			populate_sysroot) sstask="populate-sysroot"
37			;;
38			populate_lic) sstask="populate-lic"
39			;;
40			package_write_ipk) sstask="deploy-ipk"
41			;;
42			package_write_deb) sstask="deploy-deb"
43			;;
44			package_write_rpm) sstask="deploy-rpm"
45			;;
46			package) sstask="package"
47			;;
48			deploy) sstask="deploy"
49			;;
50			*)
51			;;
52		esac
53
54		echo "Removing ${sstate_dir}/${sstate_pkgspec}*_${sstask}.tgz* for $target"
55		rm -rf ${sstate_dir}/${sstate_pkgspec}*_${sstask}.tgz*
56	done
57}
58
59# Function to re-execute specified task of recipe
60function testit {
61	target=$1
62	task=$2
63
64	task=`echo $task | sed 's/_setscene//'`
65
66	if [ -f $LOGS/force.$target.$task ]; then
67		return
68	fi
69
70	case $task in
71		clean|build|cleansstate|cleanall|package|cleansstate2|package_write|package_write_ipk|package_write_rpm|package_write_deb|fetch|populate_lic) return;;
72		fetchall|devshell|buildall|listtasks|checkuri|checkuriall) return;;
73	esac
74
75	echo "Attempting target $target, task $task"
76	echo "Initial build"
77	bitbake $target -c cleansstate > $LOGS/initial.$target.$task
78	bitbake $target >> $LOGS/initial.$target.$task
79	clearsstate $target >> $LOGS/initial.$target.$task
80	echo "Re-execution build"
81	bitbake $target -c $task -f  > $LOGS/force.$target.$task
82	if [ "$?" != 0 ]; then
83		echo "FAILURE for $target $task"
84		cp $LOGS/force.$target.$task $LOGS/failed.$target.$task
85		bitbake $target -c clean > $LOGS/clean.$target.$task
86	else
87		bitbake $target >> $LOGS/force.$target.$task
88		if [ "$?" != 0 ]; then
89			echo "FAILURE2 for $target $task"
90			cp $LOGS/force.$target.$task $LOGS/failed.$target.$task
91			bitbake $target -c clean > $LOGS/clean.$target.$task
92		fi
93	fi
94	echo "Done"
95}
96
97# Go through the recipe list and these recipes' task list
98# Then re-execute them
99for target in $targets; do
100	# Remove log messages from bitbake output
101	case $target in
102		Summary*|WARNING*|Loading*|Loaded*|Package*|=====*) continue;;
103	esac
104	tasks=`bitbake $target -c listtasks | grep ^do_ | sed s/do_//`
105	for task in $tasks; do
106		testit $target $task
107	done
108done
109
110
111