Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

# Copyright (C) 2017 Free Software Foundation, Inc. 

 

# This program is free software; you can redistribute it and/or modify 

# it under the terms of the GNU General Public License as published by 

# the Free Software Foundation; either version 3 of the License, or 

# (at your option) any later version. 

# 

# This program is distributed in the hope that it will be useful, 

# but WITHOUT ANY WARRANTY; without even the implied warranty of 

# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 

# GNU General Public License for more details. 

# 

# You should have received a copy of the GNU General Public License 

# along with GCC; see the file COPYING3. If not see 

# <http://www.gnu.org/licenses/>. 

 

# Helpers to drive a testcase 

 

from collections import namedtuple 

import sys 

 

 

# This named tuple is designed to make it easy to add arguments in the 

# command-line interface of test scripts: just add a field here and an argument 

# in DejaGNU code and you are done. 

ScriptArgs = namedtuple('ScriptArgs', [ 

# Full path to the testcase source file 

'source_file', 

 

# Relative path to the generated object file (it must be in the current 

# working directory). 

'object_file' 

]) 

 

 

def parse_args(argv=None): # no-coverage 

""" 

Turn command line arguments into a ScriptArgs instance. 

 

:param list[str]|None argv: Arguments to process. If not provided, sys.argv 

is used instead. 

:rtype: ScriptArgs 

""" 

argv = sys.argv[1:] if argv is None else argv 

return ScriptArgs(*argv) 

 

 

def print_pass(message): 

"""Emit a PASS message. 

 

:param str message: Message to emit. 

""" 

print('PASS: {0}'.format(message)) 

 

 

def print_fail(message): 

"""Emit a FAIL message. 

 

:param str message: Message to emit. 

""" 

print('FAIL: {0}'.format(message)) 

 

 

def check(predicate, message): 

""" 

If `predicate` is true, emit a PASS message, otherwise emit a FAIL one. 

 

:param bool predicate: Whether the test should pass. 

:param str message: Message to emit. 

""" 

if predicate: 

print_pass(message) 

else: 

print_fail(message)