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