1/* Copyright (C) 1994-2022 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
8
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public
15 License along with the GNU C Library; if not, see
16 <https://www.gnu.org/licenses/>. */
17
18#include <stdlib.h>
19#include <stdio.h>
20#include <string.h>
21#include <support/check.h>
22
23void try (const char *name, long long int param, int value, int expected)
24{
25 if (value != expected)
26 {
27 printf (format: "%s(%#llx) expected %d got %d\n",
28 name, param, expected, value);
29 support_record_failure ();
30 }
31 else
32 printf (format: "%s(%#llx) as expected %d\n", name, param, value);
33}
34
35int
36do_test (void)
37{
38 int i;
39
40#define TEST(fct, type) \
41 try (#fct, 0, fct ((type) 0), 0); \
42 for (i=0 ; i < 8 * sizeof (type); i++) \
43 try (#fct, 1ll << i, fct (((type) 1) << i), i + 1); \
44 for (i=0 ; i < 8 * sizeof (type) ; i++) \
45 try (#fct, (~((type) 0) >> i) << i, fct ((~((type) 0) >> i) << i), i + 1);\
46 try (#fct, 0x80008000, fct ((type) 0x80008000), 16)
47
48 TEST (ffs, int);
49 TEST (ffsl, long int);
50 TEST (ffsll, long long int);
51
52 return 0;
53}
54
55#include <support/test-driver.c>
56

source code of glibc/string/test-ffs.c