aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2011-10-03 19:59:05 +0200
committerAlon Zakai <alonzakai@gmail.com>2011-10-03 19:59:05 +0200
commita9f082c2d60417730d11d2c0dc9da7e6e5ed2e00 (patch)
treebaf6d9b2d17814be17d45f90d09b74f47ebb9248
parent95420a111d0ba2154ce9953b2506f7e402b97d7b (diff)
fix test_time
-rw-r--r--src/compiler.js2
-rw-r--r--src/library.js33
-rw-r--r--system/include/libc/machine/time.h4
-rw-r--r--system/include/libc/time.h9
-rw-r--r--tests/runner.py2
-rw-r--r--tests/time/src.c4
6 files changed, 33 insertions, 21 deletions
diff --git a/src/compiler.js b/src/compiler.js
index 9bf81ba4..1639d4e7 100644
--- a/src/compiler.js
+++ b/src/compiler.js
@@ -79,5 +79,7 @@ raw = null;
// Do it
+//dprint(JSON.stringify(C_DEFINES));
+
JSify(analyzer(intertyper(lines)));
diff --git a/src/library.js b/src/library.js
index 3387a326..9b48a1a2 100644
--- a/src/library.js
+++ b/src/library.js
@@ -4584,8 +4584,8 @@ LibraryManager.library = {
// ==========================================================================
clock: function() {
- if (_clock.start === undefined) _clock.start = new Date();
- return (Date.now() - _clock.start.getTime()) * 1000;
+ if (_clock.start === undefined) _clock.start = Date.now();
+ return Math.floor((Date.now() - _clock.start) * ({{{ cDefine('CLOCKS_PER_SEC') }}}/1000));
},
time: function(ptr) {
@@ -4663,8 +4663,8 @@ LibraryManager.library = {
timegm__deps: ['mktime'],
timegm: function(tmPtr) {
_tzset();
- var offset = {{{ makeGetValue('_timezone', 0, 'i32') }}};
- var daylight = {{{ makeGetValue('_daylight', 0, 'i32') }}};
+ var offset = {{{ makeGetValue('__timezone', 0, 'i32') }}};
+ var daylight = {{{ makeGetValue('__daylight', 0, 'i32') }}};
daylight = (daylight == 1) ? 60 * 60 : 0;
var ret = _mktime(tmPtr) + offset - daylight;
return ret;
@@ -4742,29 +4742,30 @@ LibraryManager.library = {
},
// TODO: Initialize these to defaults on startup from system settings.
- tzname: null,
- daylight: null,
- timezone: null,
- tzset__deps: ['malloc', 'tzname', 'daylight', 'timezone'],
+ // Note: glibc has one fewer underscore for all of these. Also used in other related functions (timegm)
+ _tzname: null,
+ _daylight: null,
+ _timezone: null,
+ tzset__deps: ['_tzname', '_daylight', '_timezone'],
tzset: function() {
// TODO: Use (malleable) environment variables instead of system settings.
- if (_tzname !== null) return;
+ if (__tzname) return; // glibc does not need the double __
- _timezone = _malloc(QUANTUM_SIZE);
- {{{ makeSetValue('_timezone', '0', '-(new Date()).getTimezoneOffset() * 60', 'i32') }}}
+ __timezone = _malloc(QUANTUM_SIZE);
+ {{{ makeSetValue('__timezone', '0', '-(new Date()).getTimezoneOffset() * 60', 'i32') }}}
- _daylight = _malloc(QUANTUM_SIZE);
+ __daylight = _malloc(QUANTUM_SIZE);
var winter = new Date(2000, 0, 1);
var summer = new Date(2000, 6, 1);
- {{{ makeSetValue('_daylight', '0', 'Number(winter.getTimezoneOffset() != summer.getTimezoneOffset())', 'i32') }}}
+ {{{ makeSetValue('__daylight', '0', 'Number(winter.getTimezoneOffset() != summer.getTimezoneOffset())', 'i32') }}}
var winterName = winter.toString().match(/\(([A-Z]+)\)/)[1];
var summerName = summer.toString().match(/\(([A-Z]+)\)/)[1];
var winterNamePtr = allocate(intArrayFromString(winterName), 'i8', ALLOC_NORMAL);
var summerNamePtr = allocate(intArrayFromString(summerName), 'i8', ALLOC_NORMAL);
- _tzname = _malloc(2 * QUANTUM_SIZE);
- {{{ makeSetValue('_tzname', '0', 'winterNamePtr', 'i32') }}}
- {{{ makeSetValue('_tzname', QUANTUM_SIZE, 'summerNamePtr', 'i32') }}}
+ __tzname = _malloc(2 * QUANTUM_SIZE); // glibc does not need the double __
+ {{{ makeSetValue('__tzname', '0', 'winterNamePtr', 'i32') }}}
+ {{{ makeSetValue('__tzname', QUANTUM_SIZE, 'summerNamePtr', 'i32') }}}
},
stime__deps: ['$ERRNO_CODES', '__setErrNo'],
diff --git a/system/include/libc/machine/time.h b/system/include/libc/machine/time.h
index a296857d..54de2700 100644
--- a/system/include/libc/machine/time.h
+++ b/system/include/libc/machine/time.h
@@ -2,10 +2,10 @@
#define _MACHTIME_H_
#if defined(__rtems__)
-#define _CLOCKS_PER_SEC_ sysconf(_SC_CLK_TCK)
+/* XXX Emscripten #define _CLOCKS_PER_SEC_ sysconf(_SC_CLK_TCK) */
#else /* !__rtems__ */
#if defined(__arm__) || defined(__thumb__)
-#define _CLOCKS_PER_SEC_ 100
+/* XXX Emscripten #define _CLOCKS_PER_SEC_ 100 */
#endif
#endif /* !__rtems__ */
diff --git a/system/include/libc/time.h b/system/include/libc/time.h
index bc07d30f..019dd872 100644
--- a/system/include/libc/time.h
+++ b/system/include/libc/time.h
@@ -41,6 +41,9 @@ struct tm
int tm_wday;
int tm_yday;
int tm_isdst;
+ /* XXX Emscripten */
+ int tm_gmtoff;
+ char *tm_zone;
};
clock_t _EXFUN(clock, (void));
@@ -253,6 +256,12 @@ int _EXFUN(clock_getenable_attr, (clockid_t clock_id, int *attr));
#endif /* _POSIX_CPUTIME or _POSIX_THREAD_CPUTIME */
+/* XXX Emscripten */
+
+int _EXFUN(stime, (time_t *t));
+time_t _EXFUN(timegm, (struct tm *t));
+int _EXFUN(dysize, (int year));
+
#ifdef __cplusplus
}
#endif
diff --git a/tests/runner.py b/tests/runner.py
index c2f6b58e..95538ad3 100644
--- a/tests/runner.py
+++ b/tests/runner.py
@@ -1686,7 +1686,7 @@ if 'benchmark' not in str(sys.argv):
if USE_TYPED_ARRAYS == 2: return self.skip('Typed arrays = 2 truncate i64s')
src = open(path_from_root('tests', 'time', 'src.c'), 'r').read()
expected = open(path_from_root('tests', 'time', 'output.txt'), 'r').read()
- self.do_test(src, expected)
+ self.do_test(src, expected, extra_emscripten_args=['-H', 'libc/time.h'])
def test_statics(self):
# static initializers save i16 but load i8 for some reason
diff --git a/tests/time/src.c b/tests/time/src.c
index 9517b74c..aaf2878f 100644
--- a/tests/time/src.c
+++ b/tests/time/src.c
@@ -45,8 +45,8 @@ int main() {
time_t t2 = xmas2002 - 60 * 60 * 24 * 30 * 6;
tm_ptr = localtime(&t2);
time_t dst_diff = (tm_ptr->tm_isdst == 1) ? tm_ptr->tm_isdst * 60 * 60 : 0;
- printf("localtime timezone: %d\n", (timezone + tm_ptr->tm_gmtoff == dst_diff));
- printf("localtime daylight: %d\n", daylight == tm_ptr->tm_isdst);
+ printf("localtime timezone: %d\n", (_timezone + tm_ptr->tm_gmtoff == dst_diff)); // glibc needs
+ printf("localtime daylight: %d\n", _daylight == tm_ptr->tm_isdst); // no prefix "_"s
printf("localtime tzname: %d\n", (!strcmp(tzname[0], tm_ptr->tm_zone) ||
!strcmp(tzname[1], tm_ptr->tm_zone)));