Пример #1
0
int
main(int argc, char **argv)
{
    test_create_dynamic() ;
    test_create_static() ;
    test_thread_create() ;
    test_yield() ;
    test_wait() ;
    test_broadcast() ;
    test_pc() ;
    test_pc_big() ;
    test_recursive() ;
    test_sem() ;
    test_lock() ;
    test_func_pointer() ;
    test_ready() ;
    test_kill() ;
    test_reset() ;

    return 0 ;
}
Пример #2
0
int main_internal(string_array cmd_line, int num_helper_threads, ilzham &lzham_dll)
{
   comp_options options;
   options.m_max_helper_threads = num_helper_threads;

#ifdef _XBOX
   options.m_dict_size_log2 = 21;
#endif

   if (!cmd_line.size())
   {
      print_usage();
      return simple_test(lzham_dll, options);
   }

   enum op_mode_t
   {
      OP_MODE_INVALID = -1,
      OP_MODE_COMPRESS = 0,
      OP_MODE_DECOMPRESS = 1,
      OP_MODE_ALL = 2
   };

   op_mode_t op_mode = OP_MODE_INVALID;

   for (int i = 0; i < (int)cmd_line.size(); i++)
   {
      const std::string &str = cmd_line[i];
      if (str[0] == '-')
      {
         if (str.size() < 2)
         {
            print_error("Invalid option: %s\n", str.c_str());
            return EXIT_FAILURE;
         }
         switch (tolower(str[1]))
         {
            case 'u':
            {
               options.m_unbuffered_decompression = true;
               break;
            }
            case 'd':
            {
               int dict_size = atoi(str.c_str() + 2);
               if ((dict_size < LZHAM_MIN_DICT_SIZE_LOG2) || (dict_size > LZHAMTEST_MAX_POSSIBLE_DICT_SIZE))
               {
                  print_error("Invalid dictionary size: %s\n", str.c_str());
                  return EXIT_FAILURE;
               }
               options.m_dict_size_log2 = dict_size;
               break;
            }
            case 'm':
            {
               int comp_level = atoi(str.c_str() + 2);
               if ((comp_level < 0) || (comp_level > (int)LZHAM_COMP_LEVEL_UBER))
               {
                  print_error("Invalid compression level: %s\n", str.c_str());
                  return EXIT_FAILURE;
               }
               options.m_comp_level = static_cast<lzham_compress_level>(comp_level);
               break;
            }
            case 't':
            {
               int num_threads = atoi(str.c_str() + 2);
               if ((num_threads < 0) || (num_threads > LZHAM_MAX_HELPER_THREADS))
               {
                  print_error("Invalid number of helper threads: %s\n", str.c_str());
                  return EXIT_FAILURE;
               }
               options.m_max_helper_threads = num_threads;
               break;
            }
            case 'c':
            {
               options.m_compute_adler32_during_decomp = false;
               break;
            }
            case 'v':
            {
               options.m_verify_compressed_data = true;
               break;
            }
            case 'r':
            {
               options.m_randomize_params = true;
               break;
            }
            case 'p':
            {
               options.m_force_polar_codes = true;
               break;
            }
            case 'x':
            {
               options.m_extreme_parsing = true;
               break;
            }
            case 'e':
            {
               options.m_deterministic_parsing = true;
               break;
            }
            case 's':
            {
               int seed = atoi(str.c_str() + 2);
               srand(seed);
               printf("Using random seed: %i\n", seed);
               break;
            }
            default:
            {
               print_error("Invalid option: %s\n", str.c_str());
               return EXIT_FAILURE;
            }
         }

         cmd_line.erase(cmd_line.begin() + i);
         i--;

         continue;
      }

      if (str.size() != 1)
      {
         print_error("Invalid mode: %s\n", str.c_str());
         return EXIT_FAILURE;
      }
      switch (tolower(str[0]))
      {
         case 'c':
         {
            op_mode = OP_MODE_COMPRESS;
            break;
         }
         case 'd':
         {
            op_mode = OP_MODE_DECOMPRESS;
            break;
         }
         case 'a':
         {
            op_mode = OP_MODE_ALL;
            break;
         }
         default:
         {
            print_error("Invalid mode: %s\n", str.c_str());
            return EXIT_FAILURE;
         }
      }
      cmd_line.erase(cmd_line.begin() + i);
      break;
   }

   if (op_mode == OP_MODE_INVALID)
   {
      print_error("No mode specified!\n");
      print_usage();
      return EXIT_FAILURE;
   }

   printf("Using options:\n");
   options.print();
   printf("\n");

   int exit_status = EXIT_FAILURE;

   switch (op_mode)
   {
      case OP_MODE_COMPRESS:
      {
         if (cmd_line.size() < 2)
         {
            print_error("Must specify input and output filenames!\n");
            return EXIT_FAILURE;
         }
         else if (cmd_line.size() > 2)
         {
            print_error("Too many filenames!\n");
            return EXIT_FAILURE;
         }

         const std::string &src_file = cmd_line[0];
         const std::string &cmp_file = cmd_line[1];

         bool comp_result = compress_streaming(lzham_dll, src_file.c_str(), cmp_file.c_str(), options);
         if (comp_result)
            exit_status = EXIT_SUCCESS;

         if ((comp_result) && (options.m_verify_compressed_data))
         {
            char decomp_file[256];

#ifdef _XBOX
            sprintf(decomp_file, "e:\\__decomp_temp_%u__.tmp", (uint)GetTickCount());
#else
            sprintf(decomp_file, "__decomp_temp_%u__.tmp", (uint)timer::get_ms());
#endif
            if (!decompress_file(lzham_dll, cmp_file.c_str(), decomp_file, options))
            {
               print_error("Failed decompressing file \"%s\" to \"%s\"\n", cmp_file.c_str(), decomp_file);
               return EXIT_FAILURE;
            }

            printf("Comparing file \"%s\" to \"%s\"\n", decomp_file, src_file.c_str());

            if (!compare_files(decomp_file, src_file.c_str()))
            {
               print_error("Failed comparing decompressed file data while compressing \"%s\" to \"%s\"\n", src_file.c_str(), cmp_file.c_str());
               return EXIT_FAILURE;
            }
            else
            {
               printf("Decompressed file compared OK to original file.\n");
            }

            remove(decomp_file);
         }

         break;
      }
      case OP_MODE_DECOMPRESS:
      {
         if (cmd_line.size() < 2)
         {
            print_error("Must specify input and output filenames!\n");
            return EXIT_FAILURE;
         }
         else if (cmd_line.size() > 2)
         {
            print_error("Too many filenames!\n");
            return EXIT_FAILURE;
         }
         if (decompress_file(lzham_dll, cmd_line[0].c_str(), cmd_line[1].c_str(), options))
            exit_status = EXIT_SUCCESS;
         break;
      }
      case OP_MODE_ALL:
      {
         if (!cmd_line.size())
         {
            print_error("No directory specified!\n");
            return EXIT_FAILURE;
         }
         else if (cmd_line.size() != 1)
         {
            print_error("Too many filenames!\n");
            return EXIT_FAILURE;
         }
         if (test_recursive(lzham_dll, cmd_line[0].c_str(), options))
            exit_status = EXIT_SUCCESS;
         break;
      }
      default:
      {
         print_error("No mode specified!\n");
         print_usage();
         return EXIT_FAILURE;
      }
   }

   return exit_status;
}