value_nan.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2013 Centre National de la Recherche Scientifique
  4. *
  5. * StarPU is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU Lesser General Public License as published by
  7. * the Free Software Foundation; either version 2.1 of the License, or (at
  8. * your option) any later version.
  9. *
  10. * StarPU is distributed in the hope that it will be useful, but
  11. * WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  13. *
  14. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  15. */
  16. #include <config.h>
  17. #include <core/perfmodel/perfmodel.h>
  18. #include "../helper.h"
  19. #ifdef STARPU_HAVE_WINDOWS
  20. #include <io.h>
  21. #endif
  22. #define STRING "booh"
  23. int _check_number(double val, int nan)
  24. {
  25. char *tmp = "starpu_XXXXXX";
  26. char *filename = malloc(100);
  27. int id;
  28. strcpy(filename, tmp);
  29. #ifdef STARPU_HAVE_WINDOWS
  30. _mktemp(filename);
  31. id = open(filename, O_RDWR);
  32. #else
  33. id = mkstemp(filename);
  34. #endif
  35. /* fail */
  36. if (id < 0)
  37. {
  38. return 1;
  39. }
  40. /* write the double value in the file followed by a predefined string */
  41. FILE *f = fopen(filename, "w");
  42. if (!f)
  43. {
  44. FPRINTF(stderr, "Error when opening file %s\n", filename);
  45. return 1;
  46. }
  47. fprintf(f, "%lf %s\n", val, STRING);
  48. fclose(f);
  49. /* read the double value and the string back from the file */
  50. f = fopen(filename, "r");
  51. if (!f)
  52. {
  53. FPRINTF(stderr, "Error when opening file %s\n", filename);
  54. return 1;
  55. }
  56. double lat;
  57. char str[10];
  58. int x = _starpu_read_double(f, "%lf", &lat);
  59. int y = fscanf(f, "%s", str);
  60. fclose(f);
  61. /* check that what has been read is identical to what has been written */
  62. int pass;
  63. pass = (x == 1) && (y == 1);
  64. pass = pass && strcmp(str, STRING) == 0;
  65. if (nan)
  66. pass = pass && isnan(val) && isnan(lat);
  67. else
  68. pass = pass && lat == val;
  69. return pass?0:1;
  70. }
  71. int main(int argc, char **argv)
  72. {
  73. int ret;
  74. ret = _check_number(42.0, 0);
  75. FPRINTF(stderr, "%s when reading %lf\n", ret==0?"Success":"Error", 42.0);
  76. if (ret==0)
  77. {
  78. ret = _check_number(NAN, 1);
  79. FPRINTF(stderr, "%s when reading %lf\n", ret==0?"Success":"Error", NAN);
  80. }
  81. return ret;
  82. }