add permission check

disallow non-root user to execute ktap script.

Signed-off-by: Jovi Zhangwei <jovi.zhangwei@gmail.com>
use correct realloc size for ktapc table/string resize

This patch fix the coredump when ran:
./ktap samples/syscalls/errinfo.kp

Signed-off-by: Jovi Zhangwei <jovi.zhangwei@gmail.com>
fix gettimeofday_us return type to long

Reported by Yichun Zhang.
change ktap output default to stdout instead of stderr

Since we have -o option now, so change default output to stdout,
if user want to redirect to another file, use -o option.

Reported by Yichun Zhang.

Signed-off-by: Jovi Zhangwei <jovi.zhangwei@gmail.com>
use ffi.cast for type convention and add sample script skb_cast.kp

Example:
	trace net:netif_receive_skb {
        	var skb = ffi.cast("struct sk_buff *", arg1)
		print(skb.len, skb.data_len, skb.skb_iif)
	}

Now ktap can support type convention functionality, this is
a big step for ktap.

In future, there will don't need to declare 'struct sk_buff'
anymore in ktap script.

This patch also kill ffi.free, all memory allocated by ffi.new
will be free automatically when ktap thread exit.

Signed-off-by: Jovi Zhangwei <jovi.zhangwei@gmail.com>
add 'reload' build target in Makefile

Signed-off-by: Jovi Zhangwei <jovi.zhangwei@gmail.com>
add argument type validate for kp_str_fmt

This patch fix kernel crash caused by below command:
	ktap -e 'printf("%s\n", 32)'

Reported-by: YiChun Zhang (agentzh)

Signed-off-by: Jovi Zhangwei <jovi.zhangwei@gmail.com>
output lexerror message into stderr instead of stdout

Reported-by: Yichun Zhang <agentzh@gmail.com>
Signed-off-by: Jovi Zhangwei <jovi.zhangwei@gmail.com>
add a proper test scaffold and a small test suite

Add the Perl test scaffold module Test::ktap based on Test::Base, which
uses the IPC::Run3 module to automate the "ktap" program.

Detailed documentation has been added to file test/README.

v2:
    * added the "reindex" tool to automatically format the .t test
      files.
    * documented the "reindex" tool in test/README.
    * documented the "--- SKIP" feature in the test scaffold.

Signed-off-by: Yichun Zhang (agentzh) <agentzh@gmail.com>
some documentation love

* Fixed a lot of English errors.
* Fixed a lot of Markdown formatting issues.
* ktap was invented in the year 2012, not 2002.
add more gettimeofday variants and other fixes

* added new ktap builtin functions gettimeofday_ns(), gettimeofday_ms(),
  and gettimeofday_s().
* changed the internal helper C function gettimeofday_us to
  gettimeofday_ns because we can directly call the kernel API function
  getnstimeofday.
* fixed an integer overflow in the time values in the C function
  ktap_main.

Signed-off-by: Yichun Zhang (agentzh) <agentzh@gmail.com>
Update tutorial.md
remove unused allocated field for cdata ptr

Signed-off-by: Qingping Hou <qingping.hou@gmail.com>
rename ktap_cdata.u.st to ktap_cdata.u.rec

to keep it consistent with kp_cdata_new_record

Signed-off-by: Qingping Hou <qingping.hou@gmail.com>
support ffi.new on non-array type

Signed-off-by: Qingping Hou <qingping.hou@gmail.com>
update tests for non-array ffi.new

Signed-off-by: Qingping Hou <qingping.hou@gmail.com>
tiny update on README.md

Signed-off-by: Jovi Zhangwei <jovi.zhangwei@gmail.com>
port all ktap testcases into prove test framework

This patch also fix a deadloop bug:
	tick-1s {
		exit()
	}

	while (1) {}

Signed-off-by: Jovi Zhangwei <jovi.zhangwei@gmail.com>
Merge branch 'master' into android-4.4-integration

* master:
  port all ktap testcases into prove test framework
  tiny update on README.md
  update tests for non-array ffi.new
  support ffi.new on non-array type
  rename ktap_cdata.u.st to ktap_cdata.u.rec
  remove unused allocated field for cdata ptr
  Update tutorial.md
  add more gettimeofday variants and other fixes
  some documentation love
  add a proper test scaffold and a small test suite
  output lexerror message into stderr instead of stdout
  add argument type validate for kp_str_fmt
  add 'reload' build target in Makefile
  use ffi.cast for type convention and add sample script skb_cast.kp
  change ktap output default to stdout instead of stderr
  fix gettimeofday_us return type to long
  use correct realloc size for ktapc table/string resize
  add permission check