GitLab will be upgraded on 30 Jan 2023 from 2.00 pm (AEDT) to 3.00 pm (AEDT). During the update, GitLab and Mattermost services will not be available. If you have any concerns with this, please talk to us at N110 (b) CSIT building.

targetfib.py 1.27 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#!/usr/bin/env python3
# Copyright 2017 The Australian National University
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.


17
def fib(n):
John Zhang's avatar
John Zhang committed
18
    if n in (0, 1):
19
        return 1
John Zhang's avatar
John Zhang committed
20
    return fib(n - 1) + fib(n - 2)
21

22

23
DEFAULT_SCALE_FACTOR = 10
Zixian Cai's avatar
PEP 8    
Zixian Cai committed
24

25

26
27
def target(driver, args):
    from callback import get_callback
28
    cb_cls = get_callback(args[0])
29
30

    def main(argv):
31
32
        cb_param = argv[1]

John Zhang's avatar
John Zhang committed
33
        scale_factor = int(argv[2])
34
        n = int(argv[3])
John Zhang's avatar
John Zhang committed
35

36
        cb = cb_cls(cb_param)
John Zhang's avatar
John Zhang committed
37
        s = 0
38

John Zhang's avatar
John Zhang committed
39
40
41
42
        cb.begin()
        for j in range(scale_factor):
            s += fib(n)
        cb.end()
43
        cb.report()
John Zhang's avatar
John Zhang committed
44
45

        return int(s != fib(n) * scale_factor)
46
47

    return main, None
48
49
50
51
52

if __name__ == "__main__":
    import sys
    main, _ = target(None, sys.argv[1:])
    main([sys.argv[0]] + sys.argv[2:])