1*4882a593Smuzhiyun# OP-TEE sanity testsuite 2*4882a593SmuzhiyunThe optee_test git contains the source code for the TEE sanity 3*4882a593Smuzhiyuntestsuite in Linux using the ARM(R) TrustZone(R) technology. 4*4882a593SmuzhiyunIt is distributed under the GPLv2 and BSD 2-clause open-source 5*4882a593Smuzhiyunlicenses. 6*4882a593SmuzhiyunFor a general overview of OP-TEE, please see the 7*4882a593Smuzhiyun[Notice.md](Notice.md) file. 8*4882a593Smuzhiyun 9*4882a593Smuzhiyun## License 10*4882a593SmuzhiyunThe client applications (`optee_test/host/*`) are provided under the 11*4882a593Smuzhiyun[GPL-2.0](http://opensource.org/licenses/GPL-2.0) license. 12*4882a593SmuzhiyunThe user TAs (`optee_test/ta/*`) are provided under the 13*4882a593Smuzhiyun[BSD 2-Clause](http://opensource.org/licenses/BSD-2-Clause) license. 14*4882a593Smuzhiyun 15*4882a593Smuzhiyun 16*4882a593Smuzhiyun## Get and build the software 17*4882a593Smuzhiyun 18*4882a593Smuzhiyun### HOWTO build the testsuite 19*4882a593Smuzhiyun#### Standard tests 20*4882a593Smuzhiyunxtest test suite comes with a standard test suite, 21*4882a593Smuzhiyunfreely available. When installing OP-TEE through the 22*4882a593Smuzhiyun[manifest](https://github.com/OP-TEE/optee_os/blob/master/README.md#6-repo-manifests), 23*4882a593Smuzhiyunthe [build](https://github.com/OP-TEE/build) 24*4882a593Smuzhiyuncomponent provides the `xtest` target which builds optee_test. 25*4882a593SmuzhiyunIt makes use of the following environment variables: 26*4882a593Smuzhiyun* `CROSS_COMPILE_HOST`: the cross compiler used to compile the 27*4882a593Smuzhiyun Non-Secure Client Application (`host/xtest`) 28*4882a593Smuzhiyun* `CROSS_COMPILE_TA`: the cross compiler used to compile the 29*4882a593Smuzhiyun Trusted Applications (`ta`) 30*4882a593Smuzhiyun* `TA_DEV_KIT_DIR`: the path to the Trusted Application Dev Kit. 31*4882a593Smuzhiyun It can be found in optee_os repository, once optee_os has been compiled. 32*4882a593Smuzhiyun* `O`: the output repository 33*4882a593Smuzhiyun* When the application is compiled in 32bits mode, 34*4882a593Smuzhiyun `CFG_ARM32=y` must be set. 35*4882a593Smuzhiyun 36*4882a593Smuzhiyun 37*4882a593Smuzhiyun#### Extended test (Global Platform tests) 38*4882a593SmuzhiyunDevelopers can purchase the 39*4882a593Smuzhiyun[Global Platform Compliance Test suite](https://www.globalplatform.org/store.asp). 40*4882a593SmuzhiyunThis test suite comes with .xml files describing the tests and 41*4882a593Smuzhiyunthe Trusted Applications. 42*4882a593Smuzhiyun 43*4882a593SmuzhiyunStandard tests can be extended with the Global Platform test suite. 44*4882a593SmuzhiyunThe user must only: 45*4882a593Smuzhiyun* Install the Global Platform `xml` files in `$CFG_GP_PACKAGE_PATH` 46*4882a593Smuzhiyun* Run `make patch` (or call make `xtest-patch` from the `build` repository) 47*4882a593Smuzhiyun before compiling xtest. This must be run a single time after the installation 48*4882a593Smuzhiyun of OP-TEE. 49*4882a593Smuzhiyun 50*4882a593SmuzhiyunThis will: 51*4882a593Smuzhiyun* Create new Trusted Applications, that can be found in `ta/GP_xxx` 52*4882a593Smuzhiyun* Create new tests in `host/xtest`, as for example `xtest_9000.c` 53*4882a593Smuzhiyun* Patches `xtest_7000.c`, adding new tests. 54*4882a593Smuzhiyun 55*4882a593SmuzhiyunThen the tests must be compiled with `CFG_GP_PACKAGE_PATH=<path>`. 56*4882a593Smuzhiyun 57*4882a593Smuzhiyun 58*4882a593Smuzhiyun### HOWTO run xtest 59*4882a593Smuzhiyun 60*4882a593Smuzhiyun # all xtest 61*4882a593Smuzhiyun boot and execute on your target 62*4882a593Smuzhiyun $ modprobe optee_armtz 63*4882a593Smuzhiyun $ tee-supplicant & 64*4882a593Smuzhiyun $ xtest 65*4882a593Smuzhiyun 66*4882a593Smuzhiyun # single xtest 67*4882a593Smuzhiyun boot and execute on your target 68*4882a593Smuzhiyun $ modprobe optee_armtz 69*4882a593Smuzhiyun $ tee-supplicant & 70*4882a593Smuzhiyun $ xtest <testnumber> (i.e.: xtest 1001) 71*4882a593Smuzhiyun 72*4882a593Smuzhiyun # family xtest (i.e.: Family 1000) 73*4882a593Smuzhiyun boot and execute on your target 74*4882a593Smuzhiyun $ modprobe optee_armtz 75*4882a593Smuzhiyun $ tee-supplicant & 76*4882a593Smuzhiyun $ xtest _<family> (i.e.: xtest _1) 77*4882a593Smuzhiyun 78*4882a593Smuzhiyun#### Compiler flags 79*4882a593SmuzhiyunTo be able to see the full command when building you could build using following 80*4882a593Smuzhiyunflag: 81*4882a593Smuzhiyun 82*4882a593Smuzhiyun`$ make V=1` 83*4882a593Smuzhiyun 84*4882a593SmuzhiyunTo state where build files are stored use the `O` flag. 85*4882a593Smuzhiyun 86*4882a593Smuzhiyun`$ make O=$HOME/foo` 87*4882a593Smuzhiyun 88*4882a593SmuzhiyunBy default `optee_test` expects that `optee_client` is located at the same 89*4882a593Smuzhiyunfolder level. However if you build optee_client in another location, then you 90*4882a593Smuzhiyunalso would need to use (or export) the following flag: 91*4882a593Smuzhiyun 92*4882a593Smuzhiyun`$ make OPTEE_CLIENT_PATH=$HOME/my_new_location` 93*4882a593Smuzhiyun 94*4882a593Smuzhiyun## Coding standards 95*4882a593SmuzhiyunIn this project we are trying to adhere to the same coding convention as used in 96*4882a593Smuzhiyunthe Linux kernel (see 97*4882a593Smuzhiyun[CodingStyle](https://www.kernel.org/doc/Documentation/CodingStyle)). We achieve this by running 98*4882a593Smuzhiyun[checkpatch](http://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/scripts/checkpatch.pl) from Linux kernel. 99*4882a593SmuzhiyunHowever there are a few exceptions that we had to make since the code also 100*4882a593Smuzhiyunfollows GlobalPlatform standards. The exceptions are as follows: 101*4882a593Smuzhiyun 102*4882a593Smuzhiyun- CamelCase for GlobalPlatform types are allowed. 103*4882a593Smuzhiyun- And we also exclude checking third party code that we might use in this 104*4882a593Smuzhiyun project, such as LibTomCrypt, MPA, newlib (not in this particular git, but 105*4882a593Smuzhiyun those are also part of the complete TEE solution). The reason for excluding 106*4882a593Smuzhiyun and not fixing third party code is because we would probably deviate too much 107*4882a593Smuzhiyun from upstream and therefore it would be hard to rebase against those projects 108*4882a593Smuzhiyun later on (and we don't expect that it is easy to convince other software 109*4882a593Smuzhiyun projects to change coding style). 110*4882a593Smuzhiyun 111*4882a593Smuzhiyun### checkpatch 112*4882a593SmuzhiyunSince checkpatch is licensed under the terms of GNU GPL License Version 2, we 113*4882a593Smuzhiyuncannot include this script directly into this project. Therefore we have 114*4882a593Smuzhiyunwritten the Makefile so you need to explicitly point to the script by exporting 115*4882a593Smuzhiyunan environment variable, namely CHECKPATCH. So, suppose that the source code for 116*4882a593Smuzhiyunthe Linux kernel is at `$HOME/devel/linux`, then you have to export like follows: 117*4882a593Smuzhiyun 118*4882a593Smuzhiyun $ export CHECKPATCH=$HOME/devel/linux/scripts/checkpatch.pl 119*4882a593Smuzhiyunthereafter it should be possible to use one of the different checkpatch targets 120*4882a593Smuzhiyunin the [Makefile](Makefile). There are targets for checking all files, checking 121*4882a593Smuzhiyunagainst latest commit, against a certain base-commit etc. For the details, read 122*4882a593Smuzhiyunthe [Makefile](Makefile). 123