SystemC+GoogleTestを試してみた
Twitter上でSystemCでテストフレームワークが使えるかの話をしている時に
以下ページを教えてもらったので試してみました。
Using existing unit test frameworks with SystemC - Stack Overflow
ソースコード
まずはページに載っているソースコードをファイルにします。
- exor2.hxx
- main.cxx
- main_1.cxx
- main_2.cxx
- stim.hxx
- mon.hxx
これだけでは足りないので以下サイトに載っているNANDのコードをファイルにする。
ファイル名は「nand2.hxx」
googletest
googletestは以下サイトにあるので最新の1.7をダウンロード
解凍後「./configure」「make」
googletest - Google C++ Testing Framework - Google Project Hosting
cmake
googletestはcmakeを使ってビルド環境を作るっぽいのでCMakeLists.txtを作成する。
cmakeを使った事がないので見よう見まねで作成したのが↓
cmake_minimum_required(VERSION 2.6) project(sc_unit_test) #SystemC Path include_directories(/home/ginnyu-tei/work/google_test/_lib/systemc-2.3.0/include) LINK_DIRECTORIES(/home/ginnyu-tei/work/google_test/_lib/systemc-2.3.0/lib-linux64) #googletest Path include_directories(/home/ginnyu-tei/work/google_test/_lib/gtest-1.7.0/include) LINK_DIRECTORIES(/home/ginnyu-tei/work/google_test/_lib/gtest-1.7.0/lib/.libs) #main build add_executable(main main_1.cxx main_2.cxx main.cxx) target_link_libraries(main pthread systemc gtest)
googletestのライブラリパスは「libgtest.a」があるディレクトリを指定すれば良いですが
ビルド環境によっては「gtest-1.7.0/build」に入っている時があります。
ビルド
ソースコードとCMakeLists.txtを同じフォルダに入れて以下実行
[ginnyu-tei@localhost google_test]$ mkdir build [ginnyu-tei@localhost google_test]$ cd build/ [ginnyu-tei@localhost build]$ cmake .. -- The C compiler identification is GNU 4.7.2 -- The CXX compiler identification is GNU 4.7.2 -- Check for working C compiler: /usr/bin/cc -- Check for working C compiler: /usr/bin/cc -- works -- Detecting C compiler ABI info -- Detecting C compiler ABI info - done -- Check for working CXX compiler: /usr/bin/c++ -- Check for working CXX compiler: /usr/bin/c++ -- works -- Detecting CXX compiler ABI info -- Detecting CXX compiler ABI info - done -- Configuring done -- Generating done -- Build files have been written to: /home/ginnyu-tei/work/google_test/build [ginnyu-tei@localhost build]$ make Scanning dependencies of target main [ 33%] Building CXX object CMakeFiles/main.dir/main_1.cxx.o [ 66%] Building CXX object CMakeFiles/main.dir/main_2.cxx.o [100%] Building CXX object CMakeFiles/main.dir/main.cxx.o /home/ginnyu-tei/work/google_test/main.cxx: 関数 ‘int sc_main(int, char**)’ 内: /home/ginnyu-tei/work/google_test/main.cxx:25:18: 警告: warn_unused_result 属性付きで宣言されている ‘int RUN_ALL_TESTS()’ の戻り値を無視しています [-Wunused-result] Linking CXX executable main [100%] Built target main
Warningが出ているがビルドはできた。
実行ログ
[ginnyu-tei@localhost build]$ ./main SystemC 2.3.0-ASI --- Jan 9 2014 22:05:39 Copyright (c) 1996-2012 by all Contributors, ALL RIGHTS RESERVED Running main() from gtest_main.cc [==========] Running 2 tests from 1 test case. [----------] Global test environment set-up. [----------] 2 tests from systemc_test [ RUN ] systemc_test.test1 Time A B F 0 s 0 0 0 0 s 0 0 1 10 ns 0 1 1 20 ns 1 0 1 30 ns 1 1 0 Info: /OSCI/SystemC: Simulation stopped by user. [ OK ] systemc_test.test1 (1 ms) [ RUN ] systemc_test.test2 unknown file: Failure C++ exception with description "Error: (E113) insert primitive channel failed: elaboration done In file: sc_prim_channel.cpp:216" thrown in the test body. [ FAILED ] systemc_test.test2 (1 ms) [----------] 2 tests from systemc_test (2 ms total) [----------] Global test environment tear-down [==========] 2 tests from 1 test case ran. (2 ms total) [ PASSED ] 1 test. [ FAILED ] 1 test, listed below: [ FAILED ] systemc_test.test2 1 FAILED TEST [ OK ] systemc_test.test2 (2 ms) [----------] 2 tests from systemc_test (3 ms total) [----------] Global test environment tear-down [==========] 2 tests from 1 test case ran. (3 ms total) [ PASSED ] 2 tests. [ OK ] systemc_test.test1 (4 ms) [ RUN ] systemc_test.test2 Time A B F 0 s 0 0 0 0 s 0 0 1 10 ns 0 1 1 20 ns 1 0 1 30 ns 1 1 0 Info: /OSCI/SystemC: Simulation stopped by user. [ OK ] systemc_test.test2 (1 ms) [----------] 2 tests from systemc_test (5 ms total) [----------] Global test environment tear-down [==========] 2 tests from 1 test case ran. (5 ms total) [ PASSED ] 2 tests. [ OK ] systemc_test.test2 (2 ms) [----------] 2 tests from systemc_test (6 ms total) [----------] Global test environment tear-down [==========] 2 tests from 1 test case ran. (6 ms total) [ PASSED ] 2 tests. [ginnyu-tei@localhost build]$
なんかfailしてる・・・
SystemC2.2に変えてみた。
SystemC2.2で実行する際はmain_1.cxxとmain_2.cxxに以下の
includeを追加しないとエラーになった。
(別の環境では追加しなくてもビルドできたので環境依存かも)
#include <unistd.h>
SC2.3と同じ様にビルドして実行
[ginnyu-tei@localhost build]$ ./main SystemC 2.2.0 --- Jan 9 2014 23:02:22 Copyright (c) 1996-2006 by all Contributors ALL RIGHTS RESERVED Running main() from gtest_main.cc [==========] Running 2 tests from 1 test case. [----------] Global test environment set-up. [----------] 2 tests from systemc_test [ RUN ] systemc_test.test1 Time A B F 0 s 0 0 0 0 s 0 0 1 10 ns 0 1 1 20 ns 1 0 1 30 ns 1 1 0 SystemC: simulation stopped by user. [ OK ] systemc_test.test1 (1 ms) [ RUN ] systemc_test.test2 unknown file: Failure C++ exception with description "Error: (E546) sc_start called after sc_stop has been called In file: sc_simcontext.cpp:1315" thrown in the test body. [ FAILED ] systemc_test.test2 (1 ms) [----------] 2 tests from systemc_test (2 ms total) [----------] Global test environment tear-down [==========] 2 tests from 1 test case ran. (2 ms total) [ PASSED ] 1 test. [ FAILED ] 1 test, listed below: [ FAILED ] systemc_test.test2 1 FAILED TEST [ OK ] systemc_test.test2 (2 ms) [----------] 2 tests from systemc_test (3 ms total) [----------] Global test environment tear-down [==========] 2 tests from 1 test case ran. (3 ms total) [ PASSED ] 2 tests. [ OK ] systemc_test.test1 (3 ms) [ RUN ] systemc_test.test2 Time A B F 0 s 0 0 0 0 s 0 0 1 10 ns 0 1 1 20 ns 1 0 1 30 ns 1 1 0 SystemC: simulation stopped by user. [ OK ] systemc_test.test2 (1 ms) [----------] 2 tests from systemc_test (4 ms total) [----------] Global test environment tear-down [==========] 2 tests from 1 test case ran. (4 ms total) [ PASSED ] 2 tests. [ OK ] systemc_test.test2 (1 ms) [----------] 2 tests from systemc_test (5 ms total) [----------] Global test environment tear-down [==========] 2 tests from 1 test case ran. (5 ms total) [ PASSED ] 2 tests.
うーん・・・分からん・・・
STREAM Benchmarkをやってみた
STREAMというメモリ帯域を測定するベンチマークソフトがあるので試してみました。
上記ページにあるFTPサイトにはstream.exeがありますが
Windows32bit版で実行にはCygwin.dllが必要です。
私はWindows7 64bit版なのでソースコードからビルドしました。
ビルドは簡単でstream.cをダウンロードしてMinGWのgccでコンパイルするだけです。
(POSIX準拠になっているのでVisualStudioだと存在しないヘッダーがあります。)
以下が実行結果
------------------------------------------------------------- STREAM version $Revision: 5.10 $ ------------------------------------------------------------- This system uses 8 bytes per array element. ------------------------------------------------------------- Array size = 10000000 (elements), Offset = 0 (elements) Memory per array = 76.3 MiB (= 0.1 GiB). Total memory required = 228.9 MiB (= 0.2 GiB). Each kernel will be executed 10 times. The *best* time for each kernel (excluding the first iteration) will be used to compute the reported bandwidth. ------------------------------------------------------------- Your clock granularity/precision appears to be 999 microseconds. Each test below will take on the order of 24001 microseconds. (= 24 clock ticks) Increase the size of the arrays if this shows that you are not getting at least 20 clock ticks per test. ------------------------------------------------------------- WARNING -- The above is only a rough guideline. For best results, please be sure you know the precision of your system timer. ------------------------------------------------------------- Function Best Rate MB/s Avg time Min time Max time Copy: 8420.6 0.020112 0.019001 0.021001 Scale: 7999.6 0.020446 0.020001 0.021002 Add: 11428.0 0.021668 0.021001 0.026001 Triad: 10434.4 0.023557 0.023001 0.024002 ------------------------------------------------------------- Solution Validates: avg error less than 1.000000e-013 on all three arrays -------------------------------------------------------------
Terasic SoCKitのデモを実行してみた-HPS-
SoCKit System CD(Terasicのページからダウンロード)にデモが入っているので実行してみた。
HPS側は以下デモが入っています。
- hps_gpio
- hps_gsensor
- hps_lcd
- my_first_hps
デモ実行方法は「My_First_HPS.pdf]に記載されています。
my_first_hps実行方法
- C:\altera\13.0sp1\embedded\Embedded_Command_Shell.batを実行 「C:\altera\13.0sp1\embedded」はインストール先とバージョンによって変わるので注意
2.コマンドプロンプトが立ち上がるので「my_first_hps」があるディレクトリまで移動する
ベースはCygwinなので「cd /cygdrive/<ドライブレター>/」でドライブを移動できる。
3.移動後make
を実行
コンパイル済みのmy_first_hpsが入っているので一度make clean
した方がコンパイルの様子が見れます。
arm-linux-gnueabihf-gcc -g -Wall -I C:/altera/13.0sp1/embedded/ip/altera/hps/al tera_hps/hwlib/include -c main.c -o main.o arm-linux-gnueabihf-gcc -g -Wall main.o -o my_first_hps
4.ボードの電源を入れてLinuxを起動しTeraTermを接続する。
「Terasic SoCKitでLinuxをブートしてみた」と同じ
LAN経由でプログラムをSoCKitへ転送するので同一ネットワーク内にLANを接続する。
5.SoCKitのipアドレスを確認する
ifconfig
でIPを確認する。
DHCP環境でIPが割り当てられない場合はudhcpc
で割り当ててもらう
固定IP環境では多分以下コマンドでいけるはず
ifconfig eth0 <固定IPアドレス>
ifconfig eth0 netmask <サブネットマスク>
6.SocKit側のLinuxにパスワードを設定する
ファイル転送にscpを使うのでpasswd
コマンドでパスワードを設定する。
7.SocKit側のLinuxにプログラムを転送する。
scpで実行バイナリを転送する
コマンドプロンプト上で以下コマンドを実行する
scp my_first_hps root@<Soc Kit側のIPアドレス>:/home/root
「my_first_hps」が転送するファイルで「/home/root」が転送先ディレクトリ
8.実行バイナリを実行する。
TeraTerm上で./my_first_hps
root@socfpga_cyclone5:~# ./my_first_hps Hello World!
hps_gpio
H_SW0~3でONになっているSWに対応するLEDD10~13が点灯する
hps_gsensor Gセンサーの測定結果を出力する
root@socfpga_cyclone5:~# ./gsensor ===== gsensor test ===== id=E5h [1]X=-52 mg, Y=-84 mg, Z=932 mg [2]X=-20 mg, Y=-92 mg, Z=924 mg [3]X=44 mg, Y=-80 mg, Z=828 mg [4]X=-56 mg, Y=-900 mg, Z=552 mg [5]X=-20 mg, Y=-1096 mg, Z=-52 mg ・・・
hps_lcd
LCDに文字と図形を表示する
root@socfpga_cyclone5:~# ./hps_lcd Graphic LCD Demo
Terasic SoCKitでLinuxをブートしてみた
Terasic SoCKitを入手したのでLinuxをブートしてみました。
↓箱の写真。
↓ボード写真 MicroSDスロットは裏側にあります。
linuxブート方法はTerasicのページからRocketBoards.orgへの リンクがあったのでそのまま試しました。 Arrow SoCKIT Evaluation Board - How to Boot Linux
特に難しい操作はありませんが、MicroSDは付属していないので用意する必要があります。
以下ブートログ
U-Boot SPL 2012.10 (Apr 02 2013 - 18:25:57) SDRAM : Initializing MMR registers SDRAM : Calibrationg PHY SEQ.C: Preparing to start memory calibration SEQ.C: CALIBRATION PASSED DESIGNWARE SD/MMC: 0 U-Boot 2012.10 (Feb 28 2013 - 21:33:41) CPU : Altera SOCFPGA Platform BOARD : Altera SOCFPGA Cyclone 5 Board DRAM: 1 GiB MMC: DESIGNWARE SD/MMC: 0 *** Warning - bad CRC, using default environment In: serial Out: serial Err: serial Net: mii0 Warning: failed to set MAC address Hit any key to stop autoboot: 0 reading uImage 2693576 bytes read reading socfpga.dtb 7970 bytes read ## Booting kernel from Legacy Image at 00007fc0 ... Image Name: Linux-3.7.0 Image Type: ARM Linux Kernel Image (uncompressed) Data Size: 2693512 Bytes = 2.6 MiB Load Address: 00008000 Entry Point: 00008000 ## Flattened Device Tree blob at 00000100 Booting using the fdt blob at 0x00000100 XIP Kernel Image ... OK OK Loading Device Tree to 0fffa000, end 0fffef21 ... OK Starting kernel ... Booting Linux on physical CPU 0 Initializing cgroup subsys cpuset Linux version 3.7.0 (build@atull-linux1) (gcc version 4.7.3 20121106 (prerelease) (crosstool-NG linaro-1.13.1-4.7-2012.11-20121123 - Linaro GCC 2012.11) ) #1 SMP Fri Feb 15 10:15:57 CST 2013 CPU: ARMv7 Processor [413fc090] revision 0 (ARMv7), cr=10c5387d CPU: PIPT / VIPT nonaliasing data cache, VIPT aliasing instruction cache Machine: Altera SOCFPGA, model: Altera SOCFPGA Cyclone V Memory policy: ECC disabled, Data cache writealloc BUG: mapping for 0xfffec000 at 0xfffec000 out of vmalloc space PERCPU: Embedded 8 pages/cpu @80d58000 s10816 r8192 d13760 u32768 Built 1 zonelists in Zone order, mobility grouping on. Total pages: 260096 Kernel command line: console=ttyS0,57600 root=/dev/mmcblk0p2 rw rootwait PID hash table entries: 4096 (order: 2, 16384 bytes) Dentry cache hash table entries: 131072 (order: 7, 524288 bytes) Inode-cache hash table entries: 65536 (order: 6, 262144 bytes) Memory: 1024MB = 1024MB total Memory: 1034040k/1034040k available, 14536k reserved, 0K highmem Virtual kernel memory layout: vector : 0xffff0000 - 0xffff1000 ( 4 kB) fixmap : 0xfff00000 - 0xfffe0000 ( 896 kB) vmalloc : 0xc0800000 - 0xff000000 (1000 MB) lowmem : 0x80000000 - 0xc0000000 (1024 MB) modules : 0x7f000000 - 0x80000000 ( 16 MB) .text : 0x80008000 - 0x804bcb2c (4819 kB) .init : 0x804bd000 - 0x804e7a40 ( 171 kB) .data : 0x804e8000 - 0x80516e60 ( 188 kB) .bss : 0x80516e84 - 0x8054e664 ( 222 kB) SLUB: Genslabs=11, HWalign=64, Order=0-3, MinObjects=0, CPUs=2, Nodes=1 Hierarchical RCU implementation. NR_IRQS:16 nr_irqs:512 512 sched_clock: 32 bits at 100MHz, resolution 10ns, wraps every 42949ms Console: colour dummy device 80x30 Calibrating delay loop... 1594.16 BogoMIPS (lpj=7970816) pid_max: default: 32768 minimum: 301 Mount-cache hash table entries: 512 CPU: Testing write buffer coherency: ok CPU0: thread -1, cpu 0, socket 0, mpidr 80000000 Setting up static identity map for 0x38eab8 - 0x38eb10 CPU1: Booted secondary processor CPU1: thread -1, cpu 1, socket 0, mpidr 80000001 Brought up 2 CPUs SMP: Total of 2 processors activated (3188.32 BogoMIPS). devtmpfs: initialized NET: Registered protocol family 16 DMA: preallocated 256 KiB pool for atomic coherent allocations L310 cache controller enabled l2x0: 8 ways, CACHE_ID 0x410030c9, AUX_CTRL 0x32060000, Cache size: 524288 B hw-breakpoint: found 5 (+1 reserved) breakpoint and 1 watchpoint registers. hw-breakpoint: maximum watchpoint size is 4 bytes. bio: create slab <bio-0> at 0 SCSI subsystem initialized usbcore: registered new interface driver usbfs usbcore: registered new interface driver hub usbcore: registered new device driver usb Switching to clocksource timer3 NET: Registered protocol family 2 TCP established hash table entries: 131072 (order: 8, 1048576 bytes) TCP bind hash table entries: 65536 (order: 7, 524288 bytes) TCP: Hash tables configured (established 131072 bind 65536) TCP: reno registered UDP hash table entries: 512 (order: 2, 16384 bytes) UDP-Lite hash table entries: 512 (order: 2, 16384 bytes) NET: Registered protocol family 1 RPC: Registered named UNIX socket transport module. RPC: Registered udp transport module. RPC: Registered tcp transport module. RPC: Registered tcp NFSv4.1 backchannel transport module. NFS: Registering the id_resolver key type Key type id_resolver registered Key type id_legacy registered NTFS driver 2.1.30 [Flags: R/W]. jffs2: version 2.2. (NAND) 息 2001-2006 Red Hat, Inc. msgmni has been set to 2019 io scheduler noop registered (default) Serial: 8250/16550 driver, 2 ports, IRQ sharing disabled ffc02000.serial0: ttyS0 at MMIO 0xffc02000 (irq = 690) is a 8250 console [ttyS0] enabled ffc03000.serial1: ttyS1 at MMIO 0xffc03000 (irq = 691) is a 8250 brd: module loaded at24 0-0051: 4096 byte 24c32 EEPROM, writable, 32 bytes/write cadence-qspi ff705000.spi: master is unqueued, this is deprecated m25p80 spi2.0: unrecognized JEDEC id 905d10 m25p80 spi2.1: unrecognized JEDEC id ffffff cadence-qspi ff705000.spi: Cadence QSPI controller driver dw_spi_mmio fff00000.spi: master is unqueued, this is deprecated dw_spi_mmio fff01000.spi: master is unqueued, this is deprecated stmmac - user ID: 0x10, Synopsys ID: 0x37 DMA HW capability register supported Enhanced/Alternate descriptors RX Checksum Offload Engine supported (type 2) TX Checksum insertion supported libphy: stmmac: probed eth0: PHY ID 00221611 at 1 IRQ 0 (stmmac-0:01) active socfpga_phy_reset_mii writing extended registers to phyaddr 1 Initializing USB Mass Storage driver... usbcore: registered new interface driver usb-storage USB Mass Storage support registered. Dedicated Tx FIFOs mode Using DMA mode dwc_otg ffb40000.usb: DWC OTG Controller dwc_otg ffb40000.usb: new USB bus registered, assigned bus number 1 dwc_otg ffb40000.usb: irq 656, io mem 0xffb40000 Init: Port Power? op_state=b_peripheral hub 1-0:1.0: USB hub found hub 1-0:1.0: 1 port detected mousedev: PS/2 mouse device common for all mice i2c /dev entries driver Synopsys Designware Multimedia Card Interface Driver dw_mmc ff704000.dwmmc0: couldn't determine pwr-en, assuming pwr-en = 0 dw_mmc ff704000.dwmmc0: Using internal DMA controller. dw_mmc ff704000.dwmmc0: DW MMC controller at irq 667, 32 bit host data width, 1024 deep fifo dw_mmc ff704000.dwmmc0: 1 slots initialized dw_mmc ff704000.dwmmc0: Version ID is 240a mmc_host mmc0: Bus speed (slot 0) = 12500000Hz (slot req 400000Hz, actual 390625HZ div = 16) usbcore: registered new interface driver usbhid usbhid: USB HID core driver oprofile: no performance counters oprofile: using timer interrupt. TCP: cubic registered NET: Registered protocol family 17 NET: Registered protocol family 15 Key type dns_resolver registered VFP support v0.3: implementor 41 architecture 3 part 30 variant 9 rev 4 ThumbEE CPU extension supported. Registering SWP/SWPB emulation handler Waiting for root device /dev/mmcblk0p2... dw_mmc ff704000.dwmmc0: data FIFO error (status=00000800) mmc0: problem reading SD Status register. mmc_host mmc0: Bus speed (slot 0) = 12500000Hz (slot req 12500000Hz, actual 12500000HZ div = 0) mmc0: new high speed SDHC card at address e624 mmcblk0: mmc0:e624 SU08G 7.40 GiB mmcblk0: p1 p2 p3 kjournald starting. Commit interval 5 seconds EXT3-fs (mmcblk0p2): warning: maximal mount count reached, running e2fsck is recommended EXT3-fs (mmcblk0p2): using internal journal EXT3-fs (mmcblk0p2): recovery complete EXT3-fs (mmcblk0p2): mounted filesystem with ordered data mode VFS: Mounted root (ext3 filesystem) on device 179:2. devtmpfs: mounted Freeing init memory: 168K INIT: version 2.88 booting Starting Bootlog daemon: bootlogd. Configuring network interfaces... eth0: device MAC address xx:xx:xx:xx:xx:xx udhcpc (v1.20.2) started Sending discover... libphy: stmmac-0:01 - Link is Up - 1000/Full Sending discover... Sending select for 192.168.21.9... Lease of 192.168.21.9 obtained, lease time 3600 /etc/udhcpc.d/50default: Adding DNS 192.168.21.1 done. Starting portmap daemon... INIT: Entering runlevel: 5 Starting OpenBSD Secure Shell server: sshd NET: Registered protocol family 10 done. Starting syslogd/klogd: done Starting Lighttpd Web Server: lighttpd. Stopping Bootlog daemon: bootlogd. Poky 8.0 (Yocto Project 1.3 Reference Distro) 1.3 socfpga_cyclone5 ttyS0 socfpga_cyclone5 login:
T-Kernelについて調べてみた
T-Kernelについてちょっと調べたのでメモ
T-KernelはオープンソースのリアルタイムOS
T-Engineフォーラムでドキュメント・開発環境・ソースコードが公開されている。
○ドキュメント
公開仕様書にあるドキュメントはユーザー登録不要で誰でも読める。
T-Kernel 2.0 仕様書は理解しておきたい。後はまだ見てない。
○開発環境
・T-Kernel 2.00.01 Software Package
開発に必要な環境の詰め合わせ。
Windows環境はCygwin+Eclips+gcc(Interface2012年5月号(QEMU特集)に環境構築の記事がある)
Linuxは多分Eclips+gcc
開発環境にはQEMUが入っていて実機レスでソフトウェア開発可能
(ターゲットは標準T-Engineボード?)
○ソースコード
T-KernelとT-Kernel 2.0がある。
2.0はメモリキャッシュ制御機能、物理タイマ機能、ユーティリティ機能が追加されている。
ライセンスはT-License 2.0とT-License 1.0があるT-License 2.0の方がゆるい。開発者が選択可能。
ソースコードはハードウェア非依存部とボード依存部、CPU依存部に分かれている。
依存部はARM11とSH(型番忘れた)のコードが入っている。多分リファレンスボードはすぐに動く。
一から依存部を実装するのは大変そう。