blob: b9286587d5c843a24d8d8fd7decf63ee48a4e8a6 [file] [log] [blame]
George Keishinge7e91712021-09-03 11:28:44 -05001#!/usr/bin/env python3
Michael Walsh642b3552020-05-05 14:04:11 -05002
Patrick Williams20f38712022-12-08 06:18:26 -06003from gen_arg import *
4from gen_call_robot import *
5from gen_cmd import *
6from gen_misc import *
7from gen_plug_in_utils import *
Michael Walsh642b3552020-05-05 14:04:11 -05008from gen_print import *
9from gen_valid import *
Michael Walsh642b3552020-05-05 14:04:11 -050010
11# Set exit_on_error for gen_valid functions.
12set_exit_on_error(True)
13
14parser = argparse.ArgumentParser(
Patrick Williams20f38712022-12-08 06:18:26 -060015 usage="%(prog)s [OPTIONS]",
16 description=(
17 "%(prog)s will determine whether FFDC should be collected. If so, it"
18 " will return "
19 )
20 + repr(dump_ffdc_rc())
21 + ".",
Michael Walsh642b3552020-05-05 14:04:11 -050022 formatter_class=argparse.ArgumentDefaultsHelpFormatter,
Patrick Williams20f38712022-12-08 06:18:26 -060023 prefix_chars="-+",
24)
Michael Walsh642b3552020-05-05 14:04:11 -050025
26# The stock_list will be passed to gen_get_options. We populate it with the names of stock parm options we
27# want. These stock parms are pre-defined by gen_get_options.
Patrick Williams20f38712022-12-08 06:18:26 -060028stock_list = [
29 ("test_mode", get_plug_default("test_mode", 0)),
30 ("quiet", get_plug_default("quiet", 0)),
31 ("debug", get_plug_default("debug", 0)),
32]
Michael Walsh642b3552020-05-05 14:04:11 -050033
34# For now we are hard-coding this value vs adding a soft_errors=boolean entry in the parm_def file.
35FFDC_SOFT_ERRORS = 1
36
37
Patrick Williams20f38712022-12-08 06:18:26 -060038def exit_function(signal_number=0, frame=None):
Michael Walsh642b3552020-05-05 14:04:11 -050039 r"""
40 Execute whenever the program ends normally or with the signals that we catch (i.e. TERM, INT).
41
42 This function will be called by gen_exit_function().
43 """
44
45 process_robot_output_files()
46
47
48def validate_parms():
49 r"""
50 Validate program parameters, etc.
51
52 This function will be called by gen_setup().
53 """
54
55 get_plug_vars()
56
57 valid_value(AUTOBOOT_OPENBMC_HOST)
58
59
60def main():
Michael Walsh642b3552020-05-05 14:04:11 -050061 gen_setup()
62
63 print_plug_in_header()
64
65 if FFDC_COMMAND.upper() == "FAIL":
66 if AUTOBOOT_BOOT_SUCCESS == "0":
Patrick Williams20f38712022-12-08 06:18:26 -060067 print_timen(
68 "The caller wishes to dump FFDC after each boot failure."
69 )
Michael Walsh642b3552020-05-05 14:04:11 -050070 exit(dump_ffdc_rc())
71 elif FFDC_COMMAND.upper() == "ALL":
72 print_timen("The caller wishes to dump FFDC after each boot test.")
73 exit(dump_ffdc_rc())
74 elif len(FFDC_COMMAND) > 0:
75 shell_rc, out_buf = shell_cmd(FFDC_COMMAND, quiet=quiet)
76 if shell_rc != 0:
77 print_timen("The caller wishes to dump FFDC.")
78 exit(dump_ffdc_rc())
79 if FFDC_SOFT_ERRORS:
80 # Check the num_error_logs value left by the Soft_errors plug-in.
81 num_error_logs = int(restore_plug_in_value(0, "Soft_errors"))
82 if num_error_logs > 0:
Patrick Williams20f38712022-12-08 06:18:26 -060083 print_timen(
84 'The "Soft_errors" plug-in found soft_errors and the'
85 + " caller wishes to dump FFDC on soft errors."
86 )
Michael Walsh642b3552020-05-05 14:04:11 -050087 exit(dump_ffdc_rc())
88
89 print_timen("The caller does not wish for any FFDC to be collected.")
90
91
92main()