value_nan.c 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. #define STRING "booh"
  20. int _check_number(double val, int nan)
  21. {
  22. char *tmp = "starpu_XXXXXX";
  23. char *filename = malloc(100);
  24. int id;
  25. strcpy(filename, tmp);
  26. #ifdef STARPU_HAVE_WINDOWS
  27. _mktemp(filename);
  28. id = open(filename, O_RDWR);
  29. #else
  30. id = mkstemp(filename);
  31. #endif
  32. /* fail */
  33. if (id < 0)
  34. {
  35. return 1;
  36. }
  37. /* write the double value in the file followed by a predefined string */
  38. FILE *f = fopen(filename, "w");
  39. if (!f)
  40. {
  41. FPRINTF(stderr, "Error when opening file %s\n", filename);
  42. return 1;
  43. }
  44. fprintf(f, "%lf %s\n", val, STRING);
  45. fclose(f);
  46. /* read the double value and the string back from the file */
  47. f = fopen(filename, "r");
  48. if (!f)
  49. {
  50. FPRINTF(stderr, "Error when opening file %s\n", filename);
  51. return 1;
  52. }
  53. double lat;
  54. char str[10];
  55. int x = _starpu_read_double(f, "%lf", &lat);
  56. int y = fscanf(f, "%s", str);
  57. fclose(f);
  58. /* check that what has been read is identical to what has been written */
  59. int pass;
  60. pass = (x == 1) && (y == 1);
  61. pass = pass && strcmp(str, STRING) == 0;
  62. if (nan)
  63. pass = pass && isnan(val) && isnan(lat);
  64. else
  65. pass = pass && lat == val;
  66. return pass?0:1;
  67. }
  68. int main(int argc, char **argv)
  69. {
  70. int ret;
  71. ret = _check_number(42.0, 0);
  72. FPRINTF(stderr, "%s when reading %lf\n", ret==0?"Success":"Error", 42.0);
  73. if (ret==0)
  74. {
  75. ret = _check_number(NAN, 1);
  76. FPRINTF(stderr, "%s when reading %lf\n", ret==0?"Success":"Error", NAN);
  77. }
  78. return ret;
  79. }