1*49cdfc7eSAndroid Build Coastguard Worker /*
2*49cdfc7eSAndroid Build Coastguard Worker *
3*49cdfc7eSAndroid Build Coastguard Worker * Copyright (c) International Business Machines Corp., 2002
4*49cdfc7eSAndroid Build Coastguard Worker *
5*49cdfc7eSAndroid Build Coastguard Worker * This program is free software; you can redistribute it and/or modify
6*49cdfc7eSAndroid Build Coastguard Worker * it under the terms of the GNU General Public License as published by
7*49cdfc7eSAndroid Build Coastguard Worker * the Free Software Foundation; either version 2 of the License, or
8*49cdfc7eSAndroid Build Coastguard Worker * (at your option) any later version.
9*49cdfc7eSAndroid Build Coastguard Worker *
10*49cdfc7eSAndroid Build Coastguard Worker * This program is distributed in the hope that it will be useful,
11*49cdfc7eSAndroid Build Coastguard Worker * but WITHOUT ANY WARRANTY; without even the implied warranty of
12*49cdfc7eSAndroid Build Coastguard Worker * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
13*49cdfc7eSAndroid Build Coastguard Worker * the GNU General Public License for more details.
14*49cdfc7eSAndroid Build Coastguard Worker *
15*49cdfc7eSAndroid Build Coastguard Worker * You should have received a copy of the GNU General Public License
16*49cdfc7eSAndroid Build Coastguard Worker * along with this program; if not, write to the Free Software
17*49cdfc7eSAndroid Build Coastguard Worker * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18*49cdfc7eSAndroid Build Coastguard Worker */
19*49cdfc7eSAndroid Build Coastguard Worker
20*49cdfc7eSAndroid Build Coastguard Worker /* 01/02/2003 Port to LTP [email protected] */
21*49cdfc7eSAndroid Build Coastguard Worker /* 06/30/2001 Port to Linux [email protected] */
22*49cdfc7eSAndroid Build Coastguard Worker
23*49cdfc7eSAndroid Build Coastguard Worker /*
24*49cdfc7eSAndroid Build Coastguard Worker * NAME
25*49cdfc7eSAndroid Build Coastguard Worker * abs -- absolute integer value
26*49cdfc7eSAndroid Build Coastguard Worker *
27*49cdfc7eSAndroid Build Coastguard Worker * CALLS
28*49cdfc7eSAndroid Build Coastguard Worker * abs(3)
29*49cdfc7eSAndroid Build Coastguard Worker *
30*49cdfc7eSAndroid Build Coastguard Worker * ALGORITHM
31*49cdfc7eSAndroid Build Coastguard Worker * Check with variables. Also most neg value as listed
32*49cdfc7eSAndroid Build Coastguard Worker * on man page.
33*49cdfc7eSAndroid Build Coastguard Worker *
34*49cdfc7eSAndroid Build Coastguard Worker * RESTRICTIONS
35*49cdfc7eSAndroid Build Coastguard Worker * considered a long time - estimate this one
36*49cdfc7eSAndroid Build Coastguard Worker */
37*49cdfc7eSAndroid Build Coastguard Worker #define _GNU_SOURCE 1
38*49cdfc7eSAndroid Build Coastguard Worker
39*49cdfc7eSAndroid Build Coastguard Worker #include <stdio.h> /* needed by testhead.h */
40*49cdfc7eSAndroid Build Coastguard Worker #include <stdlib.h>
41*49cdfc7eSAndroid Build Coastguard Worker #include <unistd.h>
42*49cdfc7eSAndroid Build Coastguard Worker #include <ctype.h>
43*49cdfc7eSAndroid Build Coastguard Worker #include <math.h>
44*49cdfc7eSAndroid Build Coastguard Worker #include <errno.h>
45*49cdfc7eSAndroid Build Coastguard Worker #include <limits.h>
46*49cdfc7eSAndroid Build Coastguard Worker
47*49cdfc7eSAndroid Build Coastguard Worker /***** LTP Port *****/
48*49cdfc7eSAndroid Build Coastguard Worker
49*49cdfc7eSAndroid Build Coastguard Worker #include "test.h"
50*49cdfc7eSAndroid Build Coastguard Worker #define FAILED 0
51*49cdfc7eSAndroid Build Coastguard Worker #define PASSED 1
52*49cdfc7eSAndroid Build Coastguard Worker
53*49cdfc7eSAndroid Build Coastguard Worker char *TCID = "abs01";
54*49cdfc7eSAndroid Build Coastguard Worker int local_flag = PASSED;
55*49cdfc7eSAndroid Build Coastguard Worker int block_number;
56*49cdfc7eSAndroid Build Coastguard Worker FILE *temp;
57*49cdfc7eSAndroid Build Coastguard Worker int TST_TOTAL = 1;
58*49cdfc7eSAndroid Build Coastguard Worker
59*49cdfc7eSAndroid Build Coastguard Worker static void setup(void);
60*49cdfc7eSAndroid Build Coastguard Worker static int blenter(void);
61*49cdfc7eSAndroid Build Coastguard Worker static int blexit(void);
62*49cdfc7eSAndroid Build Coastguard Worker
63*49cdfc7eSAndroid Build Coastguard Worker /********************************/
64*49cdfc7eSAndroid Build Coastguard Worker
65*49cdfc7eSAndroid Build Coastguard Worker /*--------------------------------------------------------------*/
main(void)66*49cdfc7eSAndroid Build Coastguard Worker int main(void)
67*49cdfc7eSAndroid Build Coastguard Worker {
68*49cdfc7eSAndroid Build Coastguard Worker register long long i;
69*49cdfc7eSAndroid Build Coastguard Worker register int j, k, l, m;
70*49cdfc7eSAndroid Build Coastguard Worker
71*49cdfc7eSAndroid Build Coastguard Worker setup(); /* temp file is now open */
72*49cdfc7eSAndroid Build Coastguard Worker /*--------------------------------------------------------------*/
73*49cdfc7eSAndroid Build Coastguard Worker blenter();
74*49cdfc7eSAndroid Build Coastguard Worker
75*49cdfc7eSAndroid Build Coastguard Worker i = llabs(INT_MIN) + (long long)INT_MIN;
76*49cdfc7eSAndroid Build Coastguard Worker
77*49cdfc7eSAndroid Build Coastguard Worker if (i != 0) {
78*49cdfc7eSAndroid Build Coastguard Worker fprintf(temp, "abs of minimum integer failed.");
79*49cdfc7eSAndroid Build Coastguard Worker local_flag = FAILED;
80*49cdfc7eSAndroid Build Coastguard Worker }
81*49cdfc7eSAndroid Build Coastguard Worker
82*49cdfc7eSAndroid Build Coastguard Worker blexit();
83*49cdfc7eSAndroid Build Coastguard Worker /*--------------------------------------------------------------*/
84*49cdfc7eSAndroid Build Coastguard Worker blenter();
85*49cdfc7eSAndroid Build Coastguard Worker
86*49cdfc7eSAndroid Build Coastguard Worker i = llabs(0);
87*49cdfc7eSAndroid Build Coastguard Worker if (i != 0) {
88*49cdfc7eSAndroid Build Coastguard Worker fprintf(temp, "abs(0) failed, returned %lld\n", i);
89*49cdfc7eSAndroid Build Coastguard Worker local_flag = FAILED;
90*49cdfc7eSAndroid Build Coastguard Worker }
91*49cdfc7eSAndroid Build Coastguard Worker
92*49cdfc7eSAndroid Build Coastguard Worker blexit();
93*49cdfc7eSAndroid Build Coastguard Worker /*--------------------------------------------------------------*/
94*49cdfc7eSAndroid Build Coastguard Worker blenter();
95*49cdfc7eSAndroid Build Coastguard Worker
96*49cdfc7eSAndroid Build Coastguard Worker for (m = 1; m >= 0; m <<= 1) {
97*49cdfc7eSAndroid Build Coastguard Worker j = ~m;
98*49cdfc7eSAndroid Build Coastguard Worker k = j + 1;
99*49cdfc7eSAndroid Build Coastguard Worker l = abs(k);
100*49cdfc7eSAndroid Build Coastguard Worker if (l != m)
101*49cdfc7eSAndroid Build Coastguard Worker local_flag = FAILED;
102*49cdfc7eSAndroid Build Coastguard Worker }
103*49cdfc7eSAndroid Build Coastguard Worker
104*49cdfc7eSAndroid Build Coastguard Worker blexit();
105*49cdfc7eSAndroid Build Coastguard Worker /*--------------------------------------------------------------*/
106*49cdfc7eSAndroid Build Coastguard Worker /* Clean up any files created by test before call to anyfail. */
107*49cdfc7eSAndroid Build Coastguard Worker
108*49cdfc7eSAndroid Build Coastguard Worker tst_exit();
109*49cdfc7eSAndroid Build Coastguard Worker }
110*49cdfc7eSAndroid Build Coastguard Worker
111*49cdfc7eSAndroid Build Coastguard Worker /*--------------------------------------------------------------*/
112*49cdfc7eSAndroid Build Coastguard Worker
113*49cdfc7eSAndroid Build Coastguard Worker /***** LTP Port *****/
setup(void)114*49cdfc7eSAndroid Build Coastguard Worker static void setup(void)
115*49cdfc7eSAndroid Build Coastguard Worker {
116*49cdfc7eSAndroid Build Coastguard Worker temp = stderr;
117*49cdfc7eSAndroid Build Coastguard Worker }
118*49cdfc7eSAndroid Build Coastguard Worker
blenter(void)119*49cdfc7eSAndroid Build Coastguard Worker static int blenter(void)
120*49cdfc7eSAndroid Build Coastguard Worker {
121*49cdfc7eSAndroid Build Coastguard Worker local_flag = PASSED;
122*49cdfc7eSAndroid Build Coastguard Worker return (0);
123*49cdfc7eSAndroid Build Coastguard Worker }
124*49cdfc7eSAndroid Build Coastguard Worker
blexit(void)125*49cdfc7eSAndroid Build Coastguard Worker static int blexit(void)
126*49cdfc7eSAndroid Build Coastguard Worker {
127*49cdfc7eSAndroid Build Coastguard Worker (local_flag == PASSED) ? tst_resm(TPASS,
128*49cdfc7eSAndroid Build Coastguard Worker "Test passed") : tst_resm(TFAIL,
129*49cdfc7eSAndroid Build Coastguard Worker "Test failed");
130*49cdfc7eSAndroid Build Coastguard Worker return (0);
131*49cdfc7eSAndroid Build Coastguard Worker }
132*49cdfc7eSAndroid Build Coastguard Worker
133*49cdfc7eSAndroid Build Coastguard Worker /****** *****/
134