test_main.c 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. /****************************************************************************
  2. *
  3. * MODULE: test.gpde.lib
  4. *
  5. * AUTHOR(S): Original author
  6. * Soeren Gebbert soerengebbert <at> gmx <dot> de
  7. * 05 Sep 2007 Berlin
  8. *
  9. * PURPOSE: Unit and integration tests for the gmath library
  10. *
  11. * COPYRIGHT: (C) 2007 by the GRASS Development Team
  12. *
  13. * This program is free software under the GNU General Public
  14. * License (>=v2). Read the file COPYING that comes with GRASS
  15. * for details.
  16. *
  17. *****************************************************************************/
  18. #include <stdlib.h>
  19. #include <string.h>
  20. #include <grass/gis.h>
  21. #include <grass/glocale.h>
  22. #include <grass/gmath.h>
  23. #include "test_gmath_lib.h"
  24. #include "grass/gmath.h"
  25. /*- Parameters and global variables -----------------------------------------*/
  26. typedef struct {
  27. struct Option *unit, *integration, *solverbenchmark, *blasbenchmark, *rows;
  28. struct Flag *full, *testunit, *testint;
  29. } paramType;
  30. paramType param; /*Parameters */
  31. /*- prototypes --------------------------------------------------------------*/
  32. static void set_params(void); /*Fill the paramType structure */
  33. /* ************************************************************************* */
  34. /* Set up the arguments we are expecting ********************************** */
  35. /* ************************************************************************* */
  36. void set_params(void) {
  37. param.unit = G_define_option();
  38. param.unit->key = "unit";
  39. param.unit->type = TYPE_STRING;
  40. param.unit->required = NO;
  41. param.unit->options = "blas1,blas2,blas3,solver,ccmath,matconv";
  42. param.unit->description = _("Choose the unit tests to run");
  43. param.integration = G_define_option();
  44. param.integration->key = "integration";
  45. param.integration->type = TYPE_STRING;
  46. param.integration->required = NO;
  47. param.integration->options = "";
  48. param.integration->description = _("Choose the integration tests to run");
  49. param.rows = G_define_option();
  50. param.rows->key = "rows";
  51. param.rows->type = TYPE_INTEGER;
  52. param.rows->required = NO;
  53. param.rows->answer = "1000";
  54. param.rows->description = _("The size of the matrices and vectors for benchmarking");
  55. param.solverbenchmark = G_define_option();
  56. param.solverbenchmark->key = "solverbench";
  57. param.solverbenchmark->type = TYPE_STRING;
  58. param.solverbenchmark->required = NO;
  59. param.solverbenchmark->options = "krylov,direct";
  60. param.solverbenchmark->description = _("Choose solver benchmark");
  61. param.blasbenchmark = G_define_option();
  62. param.blasbenchmark->key = "blasbench";
  63. param.blasbenchmark->type = TYPE_STRING;
  64. param.blasbenchmark->required = NO;
  65. param.blasbenchmark->options = "blas2,blas3";
  66. param.blasbenchmark->description = _("Choose blas benchmark");
  67. param.testunit = G_define_flag();
  68. param.testunit->key = 'u';
  69. param.testunit->description = _("Run all unit tests");
  70. param.testint = G_define_flag();
  71. param.testint->key = 'i';
  72. param.testint->description = _("Run all integration tests");
  73. param.full = G_define_flag();
  74. param.full->key = 'a';
  75. param.full->description = _("Run all unit and integration tests");
  76. }
  77. /* ************************************************************************* */
  78. /* ************************************************************************* */
  79. /* ************************************************************************* */
  80. int main(int argc, char *argv[]) {
  81. struct GModule *module;
  82. int returnstat = 0, i;
  83. int rows = 3000;
  84. /* Initialize GRASS */
  85. G_gisinit(argv[0]);
  86. module = G_define_module();
  87. module->description
  88. = _("Performs benchmarks, unit and integration tests for the gmath library");
  89. /* Get parameters from user */
  90. set_params();
  91. if (G_parser(argc, argv))
  92. exit(EXIT_FAILURE);
  93. if (param.rows->answer)
  94. sscanf(param.rows->answer, "%i", &rows);
  95. /*Run the unit tests */
  96. if (param.testunit->answer || param.full->answer) {
  97. returnstat += unit_test_blas_level_1();
  98. returnstat += unit_test_blas_level_2();
  99. returnstat += unit_test_blas_level_3();
  100. returnstat += unit_test_solvers();
  101. returnstat += unit_test_matrix_conversion();
  102. returnstat += unit_test_ccmath_wrapper();
  103. }
  104. /*Run the integration tests */
  105. if (param.testint->answer || param.full->answer) {
  106. ;
  107. }
  108. /*Run single tests */
  109. if (!param.full->answer) {
  110. /*unit tests */
  111. if (!param.testunit->answer) {
  112. i = 0;
  113. if (param.unit->answers)
  114. while (param.unit->answers[i]) {
  115. if (strcmp(param.unit->answers[i], "blas1") == 0)
  116. returnstat += unit_test_blas_level_1();
  117. if (strcmp(param.unit->answers[i], "blas2") == 0)
  118. returnstat += unit_test_blas_level_2();
  119. if (strcmp(param.unit->answers[i], "blas3") == 0)
  120. returnstat += unit_test_blas_level_3();
  121. if (strcmp(param.unit->answers[i], "solver") == 0)
  122. returnstat += unit_test_solvers();
  123. if (strcmp(param.unit->answers[i], "ccmath") == 0)
  124. returnstat += unit_test_ccmath_wrapper();
  125. if (strcmp(param.unit->answers[i], "matconv") == 0)
  126. returnstat += unit_test_matrix_conversion();
  127. i++;
  128. }
  129. }
  130. /*integration tests */
  131. if (!param.testint->answer) {
  132. i = 0;
  133. if (param.integration->answers)
  134. while (param.integration->answers[i]) {
  135. ;
  136. }
  137. }
  138. }
  139. i = 0;
  140. if (param.solverbenchmark->answers)
  141. while (param.solverbenchmark->answers[i]) {
  142. if (strcmp(param.solverbenchmark->answers[i], "krylov") == 0)
  143. bench_solvers_krylov(rows);
  144. if (strcmp(param.solverbenchmark->answers[i], "direct") == 0)
  145. bench_solvers_direct(rows);
  146. i++;
  147. }
  148. i = 0;
  149. if (param.blasbenchmark->answers)
  150. while (param.blasbenchmark->answers[i]) {
  151. if (strcmp(param.blasbenchmark->answers[i], "blas2") == 0)
  152. bench_blas_level_2(rows);
  153. if (strcmp(param.blasbenchmark->answers[i], "blas3") == 0)
  154. bench_blas_level_3(rows);
  155. i++;
  156. }
  157. if (returnstat != 0)
  158. G_warning("Errors detected while testing the gmath lib");
  159. else
  160. G_message("\n-- gmath lib tests finished successfully --");
  161. return (returnstat);
  162. }