@ -96,40 +96,45 @@ TEST_F(EnvTest, RunMany) {
struct RunState {
struct RunState {
port : : Mutex mu ;
port : : Mutex mu ;
port : : CondVar cvar { & mu } ;
port : : CondVar cvar { & mu } ;
int last_id = 0 ;
int run_count = 0 ;
} ;
} ;
struct Callback {
struct Callback {
RunState * state_ ; // Pointer to shared state.
const int id_ ; // Order# for the execution of this callback.
RunState * const state_ ; // Pointer to shared state.
bool run = false ;
Callback ( RunState * s , int id ) : state_ ( s ) , id_ ( id ) { }
Callback ( RunState * s ) : state_ ( s ) { }
static void Run ( void * arg ) {
static void Run ( void * arg ) {
Callback * callback = reinterpret_cast < Callback * > ( arg ) ;
Callback * callback = reinterpret_cast < Callback * > ( arg ) ;
RunState * state = callback - > state_ ;
RunState * state = callback - > state_ ;
MutexLock l ( & state - > mu ) ;
MutexLock l ( & state - > mu ) ;
ASSERT_EQ ( state- > last_id , callback - > id_ - 1 ) ;
state - > last_id = callback - > id_ ;
state - > run_count + + ;
callback - > run = true ;
state - > cvar . Signal ( ) ;
state - > cvar . Signal ( ) ;
}
}
} ;
} ;
RunState state ;
RunState state ;
Callback callback1 ( & state , 1 );
Callback callback2 ( & state , 2 );
Callback callback3 ( & state , 3 );
Callback callback4 ( & state , 4 );
Callback callback1 ( & state ) ;
Callback callback2 ( & state ) ;
Callback callback3 ( & state ) ;
Callback callback4 ( & state ) ;
env_ - > Schedule ( & Callback : : Run , & callback1 ) ;
env_ - > Schedule ( & Callback : : Run , & callback1 ) ;
env_ - > Schedule ( & Callback : : Run , & callback2 ) ;
env_ - > Schedule ( & Callback : : Run , & callback2 ) ;
env_ - > Schedule ( & Callback : : Run , & callback3 ) ;
env_ - > Schedule ( & Callback : : Run , & callback3 ) ;
env_ - > Schedule ( & Callback : : Run , & callback4 ) ;
env_ - > Schedule ( & Callback : : Run , & callback4 ) ;
MutexLock l ( & state . mu ) ;
MutexLock l ( & state . mu ) ;
while ( state . last_id ! = 4 ) {
while ( state . run_count ! = 4 ) {
state . cvar . Wait ( ) ;
state . cvar . Wait ( ) ;
}
}
ASSERT_TRUE ( callback1 . run ) ;
ASSERT_TRUE ( callback2 . run ) ;
ASSERT_TRUE ( callback3 . run ) ;
ASSERT_TRUE ( callback4 . run ) ;
}
}
struct State {
struct State {
@ -175,11 +180,21 @@ TEST_F(EnvTest, TestOpenNonExistentFile) {
RandomAccessFile * random_access_file ;
RandomAccessFile * random_access_file ;
Status status =
Status status =
env_ - > NewRandomAccessFile ( non_existent_file , & random_access_file ) ;
env_ - > NewRandomAccessFile ( non_existent_file , & random_access_file ) ;
# if defined(LEVELDB_PLATFORM_CHROMIUM)
// TODO(crbug.com/760362): See comment in MakeIOError() from env_chromium.cc.
ASSERT_TRUE ( status . IsIOError ( ) ) ;
# else
ASSERT_TRUE ( status . IsNotFound ( ) ) ;
ASSERT_TRUE ( status . IsNotFound ( ) ) ;
# endif // defined(LEVELDB_PLATFORM_CHROMIUM)
SequentialFile * sequential_file ;
SequentialFile * sequential_file ;
status = env_ - > NewSequentialFile ( non_existent_file , & sequential_file ) ;
status = env_ - > NewSequentialFile ( non_existent_file , & sequential_file ) ;
# if defined(LEVELDB_PLATFORM_CHROMIUM)
// TODO(crbug.com/760362): See comment in MakeIOError() from env_chromium.cc.
ASSERT_TRUE ( status . IsIOError ( ) ) ;
# else
ASSERT_TRUE ( status . IsNotFound ( ) ) ;
ASSERT_TRUE ( status . IsNotFound ( ) ) ;
# endif // defined(LEVELDB_PLATFORM_CHROMIUM)
}
}
TEST_F ( EnvTest , ReopenWritableFile ) {
TEST_F ( EnvTest , ReopenWritableFile ) {