2
0

testsleep.c 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /* Licensed to the Apache Software Foundation (ASF) under one or more
  2. * contributor license agreements. See the NOTICE file distributed with
  3. * this work for additional information regarding copyright ownership.
  4. * The ASF licenses this file to You under the Apache License, Version 2.0
  5. * (the "License"); you may not use this file except in compliance with
  6. * the License. You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #include "time.h"
  17. #include "fspr_thread_proc.h"
  18. #include "fspr_errno.h"
  19. #include "fspr_general.h"
  20. #include "fspr_lib.h"
  21. #include <errno.h>
  22. #include <stdio.h>
  23. #include <stdlib.h>
  24. #include "testutil.h"
  25. #define SLEEP_INTERVAL 5
  26. static void sleep_one(abts_case *tc, void *data)
  27. {
  28. time_t pretime = time(NULL);
  29. time_t posttime;
  30. time_t timediff;
  31. fspr_sleep(fspr_time_from_sec(SLEEP_INTERVAL));
  32. posttime = time(NULL);
  33. /* normalize the timediff. We should have slept for SLEEP_INTERVAL, so
  34. * we should just subtract that out.
  35. */
  36. timediff = posttime - pretime - SLEEP_INTERVAL;
  37. ABTS_TRUE(tc, timediff >= 0);
  38. ABTS_TRUE(tc, timediff <= 1);
  39. }
  40. abts_suite *testsleep(abts_suite *suite)
  41. {
  42. suite = ADD_SUITE(suite)
  43. abts_run_test(suite, sleep_one, NULL);
  44. return suite;
  45. }