1# Common tests for the ConditionVariablePrinter and
2# ConditionVariableAttributesPrinter classes.
3#
4# Copyright (C) 2016-2022 Free Software Foundation, Inc.
5# This file is part of the GNU C Library.
6#
7# The GNU C Library is free software; you can redistribute it and/or
8# modify it under the terms of the GNU Lesser General Public
9# License as published by the Free Software Foundation; either
10# version 2.1 of the License, or (at your option) any later version.
11#
12# The GNU C Library is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15# Lesser General Public License for more details.
16#
17# You should have received a copy of the GNU Lesser General Public
18# License along with the GNU C Library; if not, see
19# <https://www.gnu.org/licenses/>.
20
21import sys
22
23from test_printers_common import *
24
25test_source = sys.argv[1]
26test_bin = sys.argv[2]
27printer_files = sys.argv[3:]
28printer_names = ['global glibc-pthread-locks']
29
30try:
31    init_test(test_bin, printer_files, printer_names)
32    go_to_main()
33
34    check_debug_symbol('struct pthread_condattr')
35
36    condvar_var = 'condvar'
37    condvar_to_string = 'pthread_cond_t'
38
39    attr_var = 'attr'
40    attr_to_string = 'pthread_condattr_t'
41
42    break_at(test_source, 'Set clock')
43    continue_cmd() # Go to test_setclock
44    next_cmd(2)
45    test_printer(condvar_var, condvar_to_string, {'Clock ID': 'CLOCK_REALTIME'})
46    test_printer(attr_var, attr_to_string, {'Clock ID': 'CLOCK_REALTIME'})
47
48    break_at(test_source, 'Set shared')
49    continue_cmd() # Go to test_setpshared
50    next_cmd(2)
51    test_printer(condvar_var, condvar_to_string, {'Shared': 'Yes'})
52    test_printer(attr_var, attr_to_string, {'Shared': 'Yes'})
53    next_cmd(2)
54    test_printer(condvar_var, condvar_to_string, {'Shared': 'No'})
55    test_printer(attr_var, attr_to_string, {'Shared': 'No'})
56
57    continue_cmd() # Exit
58
59except (NoLineError, pexpect.TIMEOUT) as exception:
60    print('Error: {0}'.format(exception))
61    result = FAIL
62
63except DebugError as exception:
64    print(exception)
65    result = UNSUPPORTED
66
67else:
68    print('Test succeeded.')
69    result = PASS
70
71exit(result)
72