TestMain.cc 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /**
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. */
  18. #include <signal.h>
  19. #ifndef __CYGWIN__
  20. #include <execinfo.h>
  21. #endif
  22. #include <stdexcept>
  23. #include "commons.h"
  24. #include "Buffers.h"
  25. #include "FileSystem.h"
  26. #include "NativeObjectFactory.h"
  27. #include "test_commons.h"
  28. extern "C" {
  29. static void handler(int sig);
  30. // TODO: just for debug, should be removed
  31. void handler(int sig) {
  32. void *array[10];
  33. size_t size;
  34. // print out all the frames to stderr
  35. fprintf(stderr, "Error: signal %d:\n", sig);
  36. #ifndef __CYGWIN__
  37. // get void*'s for all entries on the stack
  38. size = backtrace(array, 10);
  39. backtrace_symbols_fd(array, size, 2);
  40. #endif
  41. exit(1);
  42. }
  43. }
  44. using namespace NativeTask;
  45. typedef char * CString;
  46. int main(int argc, char ** argv) {
  47. signal(SIGSEGV, handler);
  48. CString * newArgv = new CString[argc + 1];
  49. memcpy(newArgv, argv, argc * sizeof(CString));
  50. bool gen = false;
  51. if (argc > 1) {
  52. if (string("perf") == newArgv[1]) {
  53. newArgv[1] = (char *)"--gtest_filter=Perf.*";
  54. } else if (string("noperf") == newArgv[1]) {
  55. newArgv[1] = (char *)"--gtest_filter=-Perf.*";
  56. } else if (string("gen") == newArgv[1]) {
  57. gen = true;
  58. }
  59. }
  60. testing::InitGoogleTest(&argc, newArgv);
  61. if (argc > 0) {
  62. int skip = gen ? 2 : 1;
  63. TestConfig.parse(argc - skip, (const char **)(newArgv + skip));
  64. }
  65. delete [] newArgv;
  66. try {
  67. if (gen == true) {
  68. string type = TestConfig.get("generate.type", "word");
  69. string codec = TestConfig.get("generate.codec", "");
  70. int64_t len = TestConfig.getInt("generate.length", 1024);
  71. string temp;
  72. GenerateKVTextLength(temp, len, type);
  73. if (codec.length() == 0) {
  74. fprintf(stdout, "%s", temp.c_str());
  75. } else {
  76. OutputStream * fout = FileSystem::getLocal().create("/dev/stdout");
  77. AppendBuffer app = AppendBuffer();
  78. app.init(128 * 1024, fout, codec);
  79. app.write(temp.data(), temp.length());
  80. fout->close();
  81. delete fout;
  82. }
  83. NativeObjectFactory::Release();
  84. return 0;
  85. } else {
  86. int ret = RUN_ALL_TESTS();
  87. NativeObjectFactory::Release();
  88. return ret;
  89. }
  90. } catch (std::exception & e) {
  91. fprintf(stderr, "Exception: %s", e.what());
  92. NativeObjectFactory::Release();
  93. return 1;
  94. }
  95. }