blob: 87270ffee8b99a49a2d056d6f1b5d5c7dbe29c48 [file] [log] [blame]
Alexandre Lision8af73cb2013-12-10 14:11:20 -05001/* $Id: os.c 3841 2011-10-24 09:28:13Z ming $ */
Tristan Matthews0a329cc2013-07-17 13:20:14 -04002/*
3 * Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
4 * Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20#include "test.h"
21#include <pj/log.h>
22#include <pj/os.h>
23
24#if INCLUDE_OS_TEST
25static int endianness_test32(void)
26{
27 union t
28 {
29 pj_uint32_t u32;
30 pj_uint16_t u16[2];
31 pj_uint8_t u8[4];
32 } t;
33
34 PJ_LOG(3,("", " Testing endianness.."));
35
36 t.u32 = 0x11223344;
37
38#if defined(PJ_IS_LITTLE_ENDIAN) && PJ_IS_LITTLE_ENDIAN
39 PJ_LOG(3,("", " Library is set to little endian"));
40
41# if defined(PJ_IS_BIG_ENDIAN) && PJ_IS_BIG_ENDIAN
42# error Error: Both PJ_IS_LITTLE_ENDIAN and PJ_IS_BIG_ENDIAN are set!
43# endif
44
45 if ((t.u16[0] & 0xFFFF) != 0x3344 ||
46 (t.u16[1] & 0xFFFF) != 0x1122)
47 {
48 PJ_LOG(3,("", " Error: wrong 16bit values 0x%x and 0x%x",
49 (t.u16[0] & 0xFFFF), (t.u16[1] & 0xFFFF)));
50 return 10;
51 }
52
53 if ((t.u8[0] & 0xFF) != 0x44 ||
54 (t.u8[1] & 0xFF) != 0x33 ||
55 (t.u8[2] & 0xFF) != 0x22 ||
56 (t.u8[3] & 0xFF) != 0x11)
57 {
58 PJ_LOG(3,("", " Error: wrong 8bit values"));
59 return 12;
60 }
61
62#elif defined(PJ_IS_BIG_ENDIAN) && PJ_IS_BIG_ENDIAN
63 PJ_LOG(3,("", " Library is set to big endian"));
64
65 if ((t.u16[0] & 0xFFFF) != 0x1122 ||
66 (t.u16[1] & 0xFFFF) != 0x3344)
67 {
68 PJ_LOG(3,("", " Error: wrong 16bit values 0x%x and 0x%x",
69 (t.u16[0] & 0xFFFF), (t.u16[1] & 0xFFFF)));
70 return 20;
71 }
72
73 if ((t.u8[0] & 0xFF) != 0x11 ||
74 (t.u8[1] & 0xFF) != 0x22 ||
75 (t.u8[2] & 0xFF) != 0x33 ||
76 (t.u8[3] & 0xFF) != 0x44)
77 {
78 PJ_LOG(3,("", " Error: wrong 8bit values"));
79 return 22;
80 }
81
82# if defined(PJ_IS_LITTLE_ENDIAN) && PJ_IS_LITTLE_ENDIAN
83# error Error: Both PJ_IS_LITTLE_ENDIAN and PJ_IS_BIG_ENDIAN are set!
84# endif
85
86
87#else
88# error Error: Endianness is not set properly!
89#endif
90
91 return 0;
92}
93
94int os_test(void)
95{
96 const pj_sys_info *si;
97 int rc = 0;
98
99 PJ_LOG(3,("", " Sys info:"));
100 si = pj_get_sys_info();
101 PJ_LOG(3,("", " machine: %s", si->machine.ptr));
102 PJ_LOG(3,("", " os_name: %s", si->os_name.ptr));
103 PJ_LOG(3,("", " os_ver: 0x%x", si->os_ver));
104 PJ_LOG(3,("", " sdk_name: %s", si->sdk_name.ptr));
105 PJ_LOG(3,("", " sdk_ver: 0x%x", si->sdk_ver));
106 PJ_LOG(3,("", " info: %s", si->info.ptr));
107
108 rc = endianness_test32();
109
110 return rc;
111}
112
113#else
114int dummy_os_var;
115#endif
116