mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-02-06 20:45:54 +01:00
add test case where (fake) sms messages never arrive
This commit is contained in:
parent
352d87a327
commit
2d8ac995b7
4 changed files with 62 additions and 44 deletions
|
@ -639,6 +639,7 @@ typedef enum {
|
|||
,CMD_DROPSENDRELAY
|
||||
,CMD_DROPRCVRELAY
|
||||
,CMD_DROPSENDSMS
|
||||
,CMD_SMSFAILPCT
|
||||
,CMD_DROPRCVSMS
|
||||
,CMD_FORCECHANNEL
|
||||
|
||||
|
@ -762,6 +763,7 @@ static CmdInfoRec CmdInfoRecs[] = {
|
|||
,{ CMD_DROPSENDRELAY, false, "drop-send-relay", "start new games with relay send disabled" }
|
||||
,{ CMD_DROPRCVRELAY, false, "drop-receive-relay", "start new games with relay receive disabled" }
|
||||
,{ CMD_DROPSENDSMS, false, "drop-send-sms", "start new games with sms send disabled" }
|
||||
,{ CMD_SMSFAILPCT, true, "sms-fail-pct", "percent of sms sends, randomly chosen, never arrive" }
|
||||
,{ CMD_DROPRCVSMS, false, "drop-receive-sms", "start new games with sms receive disabled" }
|
||||
,{ CMD_FORCECHANNEL, true, "force-channel", "force (clients) to use this hostid/channel" }
|
||||
|
||||
|
@ -2445,6 +2447,10 @@ main( int argc, char** argv )
|
|||
case CMD_DROPSENDSMS:
|
||||
mainParams.commsDisableds[COMMS_CONN_SMS][1] = XP_TRUE;
|
||||
break;
|
||||
case CMD_SMSFAILPCT:
|
||||
mainParams.smsSendFailPct = atoi(optarg);
|
||||
XP_ASSERT( mainParams.smsSendFailPct >= 0 && mainParams.smsSendFailPct <= 100 );
|
||||
break;
|
||||
case CMD_DROPRCVSMS:
|
||||
mainParams.commsDisableds[COMMS_CONN_SMS][0] = XP_TRUE;
|
||||
break;
|
||||
|
|
|
@ -114,64 +114,74 @@ unlock_queue( LinSMSData* storage )
|
|||
}
|
||||
|
||||
static XP_S16
|
||||
send_sms( LinSMSData* storage, XWStreamCtxt* stream,
|
||||
const XP_UCHAR* phone, XP_U16 port )
|
||||
write_fake_sms( LaunchParams* params, XWStreamCtxt* stream,
|
||||
const XP_UCHAR* phone, XP_U16 port )
|
||||
{
|
||||
const XP_U8* buf = stream_getPtr( stream );
|
||||
XP_U16 buflen = stream_getSize( stream );
|
||||
XP_LOGF( "%s(phone=%s, port=%d, len=%d)", __func__, phone,
|
||||
port, buflen );
|
||||
XP_S16 nSent;
|
||||
XP_U16 pct = XP_RANDOM() % 100;
|
||||
XP_Bool skipWrite = pct < params->smsSendFailPct;
|
||||
|
||||
XP_S16 nSent = -1;
|
||||
XP_ASSERT( !!storage );
|
||||
char path[256];
|
||||
if ( skipWrite ) {
|
||||
nSent = stream_getSize( stream );
|
||||
XP_LOGF( "%s(): dropping sms msg of len %d to phone %s", __func__,
|
||||
nSent, phone );
|
||||
} else {
|
||||
LinSMSData* storage = getStorage( params );
|
||||
const XP_U8* buf = stream_getPtr( stream );
|
||||
XP_U16 buflen = stream_getSize( stream );
|
||||
XP_LOGF( "%s(phone=%s, port=%d, len=%d)", __func__, phone,
|
||||
port, buflen );
|
||||
|
||||
lock_queue( storage );
|
||||
XP_ASSERT( !!storage );
|
||||
char path[256];
|
||||
|
||||
lock_queue( storage );
|
||||
|
||||
#ifdef DEBUG
|
||||
gchar* str64 = g_base64_encode( buf, buflen );
|
||||
gchar* str64 = g_base64_encode( buf, buflen );
|
||||
#endif
|
||||
|
||||
formatQueuePath( phone, port, path, sizeof(path) );
|
||||
formatQueuePath( phone, port, path, sizeof(path) );
|
||||
|
||||
/* Random-number-based name is fine, as we pick based on age. */
|
||||
int rint = makeRandomInt();
|
||||
g_mkdir_with_parents( path, 0777 ); /* just in case */
|
||||
int len = strlen( path );
|
||||
snprintf( &path[len], sizeof(path)-len, "/%u", rint );
|
||||
/* Random-number-based name is fine, as we pick based on age. */
|
||||
int rint = makeRandomInt();
|
||||
g_mkdir_with_parents( path, 0777 ); /* just in case */
|
||||
int len = strlen( path );
|
||||
snprintf( &path[len], sizeof(path)-len, "/%u", rint );
|
||||
|
||||
XP_UCHAR sms[buflen*2]; /* more like (buflen*4/3) */
|
||||
XP_U16 smslen = sizeof(sms);
|
||||
binToSms( sms, &smslen, buf, buflen );
|
||||
XP_ASSERT( smslen == strlen(sms) );
|
||||
XP_LOGF( "%s: writing msg to %s", __func__, path );
|
||||
XP_UCHAR sms[buflen*2]; /* more like (buflen*4/3) */
|
||||
XP_U16 smslen = sizeof(sms);
|
||||
binToSms( sms, &smslen, buf, buflen );
|
||||
XP_ASSERT( smslen == strlen(sms) );
|
||||
XP_LOGF( "%s: writing msg to %s", __func__, path );
|
||||
|
||||
#ifdef DEBUG
|
||||
XP_ASSERT( !strcmp( str64, sms ) );
|
||||
g_free( str64 );
|
||||
XP_ASSERT( !strcmp( str64, sms ) );
|
||||
g_free( str64 );
|
||||
|
||||
XP_U8 testout[buflen];
|
||||
XP_U16 lenout = sizeof( testout );
|
||||
XP_ASSERT( smsToBin( testout, &lenout, sms, smslen ) );
|
||||
XP_ASSERT( lenout == buflen );
|
||||
// valgrind doesn't like this; punting on figuring out
|
||||
// XP_ASSERT( XP_MEMCMP( testout, buf, smslen ) );
|
||||
XP_U8 testout[buflen];
|
||||
XP_U16 lenout = sizeof( testout );
|
||||
XP_ASSERT( smsToBin( testout, &lenout, sms, smslen ) );
|
||||
XP_ASSERT( lenout == buflen );
|
||||
// valgrind doesn't like this; punting on figuring out
|
||||
// XP_ASSERT( XP_MEMCMP( testout, buf, smslen ) );
|
||||
#endif
|
||||
|
||||
FILE* fp = fopen( path, "w" );
|
||||
XP_ASSERT( !!fp );
|
||||
(void)fprintf( fp, ADDR_FMT, storage->myPhone, storage->myPort );
|
||||
(void)fprintf( fp, "%s\n", sms );
|
||||
fclose( fp );
|
||||
sync();
|
||||
FILE* fp = fopen( path, "w" );
|
||||
XP_ASSERT( !!fp );
|
||||
(void)fprintf( fp, ADDR_FMT, storage->myPhone, storage->myPort );
|
||||
(void)fprintf( fp, "%s\n", sms );
|
||||
fclose( fp );
|
||||
sync();
|
||||
|
||||
unlock_queue( storage );
|
||||
unlock_queue( storage );
|
||||
|
||||
nSent = buflen;
|
||||
nSent = buflen;
|
||||
|
||||
LOG_RETURNF( "%d", nSent );
|
||||
LOG_RETURNF( "%d", nSent );
|
||||
}
|
||||
return nSent;
|
||||
} /* linux_sms_send */
|
||||
} /* write_fake_sms */
|
||||
|
||||
static XP_S16
|
||||
decodeAndDelete( LinSMSData* storage, const gchar* name,
|
||||
|
@ -350,8 +360,7 @@ linux_sms_invite( LaunchParams* params, const CurGameInfo* gi,
|
|||
|
||||
addrToStream( stream, addr );
|
||||
|
||||
LinSMSData* storage = getStorage( params );
|
||||
send_sms( storage, stream, toPhone, toPort );
|
||||
write_fake_sms( params, stream, toPhone, toPort );
|
||||
|
||||
stream_destroy( stream );
|
||||
}
|
||||
|
@ -381,8 +390,7 @@ doSend( LaunchParams* params, const XP_U8* buf,
|
|||
stream_putU32( stream, gameID );
|
||||
stream_putBytes( stream, buf, buflen );
|
||||
|
||||
LinSMSData* storage = getStorage( params );
|
||||
(void)send_sms( storage, stream, phone, port );
|
||||
(void)write_fake_sms( params, stream, phone, port );
|
||||
stream_destroy( stream );
|
||||
}
|
||||
|
||||
|
|
|
@ -59,6 +59,7 @@ typedef struct LaunchParams {
|
|||
char* dbName;
|
||||
sqlite3* pDb; /* null unless opened */
|
||||
XP_U16 saveFailPct;
|
||||
XP_U16 smsSendFailPct;
|
||||
const XP_UCHAR* playerDictNames[MAX_NUM_PLAYERS];
|
||||
#ifdef USE_SQLITE
|
||||
char* dbFileName;
|
||||
|
|
|
@ -393,6 +393,8 @@ def build_cmds(args):
|
|||
PARAMS += ['--use-udp']
|
||||
if args.ADD_SMS:
|
||||
PARAMS += [ '--sms-number', PHONE_BASE + str(DEV - 1) ]
|
||||
if args.SMS_FAIL_PCT > 0:
|
||||
PARAMS += [ '--sms-fail-pct', args.SMS_FAIL_PCT ]
|
||||
if DEV > 1:
|
||||
PARAMS += [ '--server-sms-number', PHONE_BASE + '0' ]
|
||||
|
||||
|
@ -655,6 +657,7 @@ def mkParser():
|
|||
parser.add_argument('--trade-pct', dest = 'TRADE_PCT', default = 0, type = int)
|
||||
|
||||
parser.add_argument('--add-sms', dest = 'ADD_SMS', default = False, action = 'store_true')
|
||||
parser.add_argument('--sms-fail-pct', dest = 'SMS_FAIL_PCT', default = 0, type = int)
|
||||
parser.add_argument('--remove-relay', dest = 'ADD_RELAY', default = True, action = 'store_false')
|
||||
|
||||
parser.add_argument('--with-valgrind', dest = 'VALGRIND', default = False,
|
||||
|
|
Loading…
Add table
Reference in a new issue