testUtil.h revision 8eea4fcdf2a829e01e8114a9572573cae98f2a6e
1/* 2 * Copyright (C) 2010 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * 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 */ 17 18#ifndef _TESTUTIL_H_ 19#define _TESTUTIL_H_ 20 21#include <stdint.h> 22#include <stdio.h> 23#include <sys/time.h> 24 25__BEGIN_DECLS 26 27// Time Utilities 28struct timespec double2ts(double amt); 29struct timeval double2tv(double amt); 30double ts2double(const struct timespec *val); 31double tv2double(const struct timeval *val); 32struct timespec tsDelta(const struct timespec *first, 33 const struct timespec *second); 34struct timeval tvDelta(const struct timeval *first, 35 const struct timeval *second); 36 37void testDelay(float amt); 38 39// Pseudo Random Utilities 40int testRandBool(void); 41uint32_t testRand(void); 42uint32_t testRandMod(uint32_t mod); 43double testRandFract(void); 44 45// Testcase Output 46void testSetLogCatTag(const char *tag); 47const char *testGetLogCatTag(void); 48void testPrint(FILE *stream, const char *fmt, ...); 49#define testPrintI(...) do { \ 50 testPrint(stdout, __VA_ARGS__); \ 51 } while (0) 52#define testPrintE(...) do { \ 53 testPrint(stderr, __VA_ARGS__); \ 54 } while (0) 55 56// Hex Dump 57void testXDump(const void *buf, size_t size); 58void testXDumpSetIndent(uint8_t indent); 59uint8_t testXDumpGetIndent(void); 60void testXDumpSetOffset(uint64_t offset); 61uint64_t testXDumpGetOffset(void); 62 63// Command Execution 64void testExecCmd(const char *cmd); 65 66__END_DECLS 67 68#endif 69