Repository: Konstantin8105/c4go
Pull request #116 (2018-05-24 08:54:08)

CSTD: sys/time.h: add test

codecov[bot]: # [Codecov](https://codecov.io/gh/Konstantin8105/c4go/pull/116?src=pr&el=h1) Report
> Merging [#116](https://codecov.io/gh/Konstantin8105/c4go/pull/116?src=pr&el=desc) into [master](https://codecov.io/gh/Konstantin8105/c4go/commit/89806cdbfa64f32819a686bec0f42b4e5b58d28c?src=pr&el=desc) will **increase** coverage by `0.19%`.
> The diff coverage is `100%`.

[![Impacted file tree graph](https://codecov.io/gh/Konstantin8105/c4go/pull/116/graphs/tree.svg?width=650&token=esH2rHXlZ2&height=150&src=pr)](https://codecov.io/gh/Konstantin8105/c4go/pull/116?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##           master     #116      +/-   ##
==========================================
+ Coverage   86.83%   87.02%   +0.19%     
==========================================
  Files         185      185              
  Lines       10307    10321      +14     
==========================================
+ Hits         8950     8982      +32     
+ Misses        938      927      -11     
+ Partials      419      412       -7
```


| [Impacted Files](https://codecov.io/gh/Konstantin8105/c4go/pull/116?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [noarch/sys\_time.go](https://codecov.io/gh/Konstantin8105/c4go/pull/116/diff?src=pr&el=tree#diff-bm9hcmNoL3N5c190aW1lLmdv) | `100% <ø> (ø)` | :arrow_up: |
| [program/definition\_struct.go](https://codecov.io/gh/Konstantin8105/c4go/pull/116/diff?src=pr&el=tree#diff-cHJvZ3JhbS9kZWZpbml0aW9uX3N0cnVjdC5nbw==) | `100% <100%> (ø)` | :arrow_up: |
| [transpiler/call.go](https://codecov.io/gh/Konstantin8105/c4go/pull/116/diff?src=pr&el=tree#diff-dHJhbnNwaWxlci9jYWxsLmdv) | `80.83% <0%> (+2.36%)` | :arrow_up: |
| [transpiler/cast.go](https://codecov.io/gh/Konstantin8105/c4go/pull/116/diff?src=pr&el=tree#diff-dHJhbnNwaWxlci9jYXN0Lmdv) | `77.46% <0%> (+2.81%)` | :arrow_up: |
| [transpiler/bind.go](https://codecov.io/gh/Konstantin8105/c4go/pull/116/diff?src=pr&el=tree#diff-dHJhbnNwaWxlci9iaW5kLmdv) | `92.62% <0%> (+4.09%)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/Konstantin8105/c4go/pull/116?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/Konstantin8105/c4go/pull/116?src=pr&el=footer). Last update [89806cd...1b5603f](https://codecov.io/gh/Konstantin8105/c4go/pull/116?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).


Patch:
diff --git a/noarch/sys_time.go b/noarch/sys_time.go
index 278d7ff..4c26635 100644
--- a/noarch/sys_time.go
+++ b/noarch/sys_time.go
@@ -12,6 +12,11 @@ type Timezone struct {
 	TzDsttime     int // type of DST correction
 }
 
+type Itimeval struct {
+	ItInterval Timeval
+	ItValue    Timeval
+}
+
 // Gettimeofday - gettimeofday from <sys/time.h>
 func Gettimeofday(tv []Timeval, tz []Timezone) int {
 	return -1
diff --git a/program/definition_struct.go b/program/definition_struct.go
index db1ec27..51aeb63 100644
--- a/program/definition_struct.go
+++ b/program/definition_struct.go
@@ -105,6 +105,24 @@ func (p *Program) initializationStructs() {
 		},
 	}
 
+	// sys/time.h
+	p.Structs["struct itimerval"] = &Struct{
+		Name: "struct itimerval",
+		Type: StructType,
+		Fields: map[string]interface{}{
+			"it_interval": "struct timeval",
+			"it_value":    "struct timeval",
+		},
+	}
+	p.Structs["c4go_struct itimerval"] = &Struct{
+		Name: "github.com/Konstantin8105/c4go/noarch.Itimeval",
+		Type: StructType,
+		Fields: map[string]interface{}{
+			"it_interval": "ItInterval",
+			"it_value":    "ItValue",
+		},
+	}
+
 	// sys/time.h
 	p.Structs["struct timeval"] = &Struct{
 		Name: "struct timeval",


Test patch:
diff --git a/tests/sys_time.c b/tests/sys_time.c
new file mode 100644
index 0000000..19f9b17
--- /dev/null
+++ b/tests/sys_time.c
@@ -0,0 +1,43 @@
+#include <stdio.h>
+#include <assert.h>
+#include <signal.h>
+#include <unistd.h>
+#include <sys/time.h>
+
+#include "tests.h"
+
+void handler(int signo)
+{
+	static const char msg[] = "\n*** Timer expired, you lose ***\n";
+	assert(signo == SIGALRM);
+	write(2, msg, sizeof(msg) - 1);
+	exit(1);
+}
+
+int main(void)
+{
+    plan(1);
+
+	struct itimerval tval;
+	char string[BUFSIZ];
+
+	timerclear(& tval.it_interval);	/* zero interval means no reset of timer */
+	timerclear(& tval.it_value);
+
+	tval.it_value.tv_sec = 10;	/* 10 second timeout */
+
+	(void) signal(SIGALRM, handler);
+
+	printf("You have ten seconds to enter\nyour name, rank, and serial number: ");
+
+	(void) setitimer(ITIMER_REAL, & tval, NULL);
+	if (fgets(string, sizeof string, stdin) != NULL) {
+		(void) setitimer(ITIMER_REAL, NULL, NULL);	/* turn off timer */
+		/* process rest of data, diagnostic print for illustration */
+		printf("I'm glad you are being cooperative.\n");
+		pass("ok");
+	} else
+		printf("\nEOF, eh?  We won't give up so easily!\n");
+
+    done_testing();
+}