test_main.c 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  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->keywords = _("test, gmath");
  88. module->description
  89. = _("Performs benchmarks, unit and integration tests for the gmath library");
  90. /* Get parameters from user */
  91. set_params();
  92. if (G_parser(argc, argv))
  93. exit(EXIT_FAILURE);
  94. if (param.rows->answer)
  95. sscanf(param.rows->answer, "%i", &rows);
  96. /*Run the unit tests */
  97. if (param.testunit->answer || param.full->answer) {
  98. returnstat += unit_test_blas_level_1();
  99. returnstat += unit_test_blas_level_2();
  100. returnstat += unit_test_blas_level_3();
  101. returnstat += unit_test_solvers();
  102. returnstat += unit_test_matrix_conversion();
  103. returnstat += unit_test_ccmath_wrapper();
  104. }
  105. /*Run the integration tests */
  106. if (param.testint->answer || param.full->answer) {
  107. ;
  108. }
  109. /*Run single tests */
  110. if (!param.full->answer) {
  111. /*unit tests */
  112. if (!param.testunit->answer) {
  113. i = 0;
  114. if (param.unit->answers)
  115. while (param.unit->answers[i]) {
  116. if (strcmp(param.unit->answers[i], "blas1") == 0)
  117. returnstat += unit_test_blas_level_1();
  118. if (strcmp(param.unit->answers[i], "blas2") == 0)
  119. returnstat += unit_test_blas_level_2();
  120. if (strcmp(param.unit->answers[i], "blas3") == 0)
  121. returnstat += unit_test_blas_level_3();
  122. if (strcmp(param.unit->answers[i], "solver") == 0)
  123. returnstat += unit_test_solvers();
  124. if (strcmp(param.unit->answers[i], "ccmath") == 0)
  125. returnstat += unit_test_ccmath_wrapper();
  126. if (strcmp(param.unit->answers[i], "matconv") == 0)
  127. returnstat += unit_test_matrix_conversion();
  128. i++;
  129. }
  130. }
  131. /*integration tests */
  132. if (!param.testint->answer) {
  133. i = 0;
  134. if (param.integration->answers)
  135. while (param.integration->answers[i]) {
  136. ;
  137. }
  138. }
  139. }
  140. i = 0;
  141. if (param.solverbenchmark->answers)
  142. while (param.solverbenchmark->answers[i]) {
  143. if (strcmp(param.solverbenchmark->answers[i], "krylov") == 0)
  144. bench_solvers_krylov(rows);
  145. if (strcmp(param.solverbenchmark->answers[i], "direct") == 0)
  146. bench_solvers_direct(rows);
  147. i++;
  148. }
  149. i = 0;
  150. if (param.blasbenchmark->answers)
  151. while (param.blasbenchmark->answers[i]) {
  152. if (strcmp(param.blasbenchmark->answers[i], "blas2") == 0)
  153. bench_blas_level_2(rows);
  154. if (strcmp(param.blasbenchmark->answers[i], "blas3") == 0)
  155. bench_blas_level_3(rows);
  156. i++;
  157. }
  158. if (returnstat != 0)
  159. G_warning("Errors detected while testing the gmath lib");
  160. else
  161. G_message("\n-- gmath lib tests finished successfully --");
  162. return (returnstat);
  163. }