nsprpub/pr/tests/dbmalloc1.c

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
michael@0 2 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5
michael@0 6 /***********************************************************************
michael@0 7 **
michael@0 8 ** Name: dbmalloc1.c (OBSOLETE)
michael@0 9 **
michael@0 10 ** Description: Tests PR_SetMallocCountdown PR_ClearMallocCountdown functions.
michael@0 11 **
michael@0 12 ** Modification History:
michael@0 13 ** 14-May-97 AGarcia- Converted the test to accomodate the debug_mode flag.
michael@0 14 ** The debug mode will print all of the printfs associated with this test.
michael@0 15 ** The regress mode will be the default mode. Since the regress tool limits
michael@0 16 ** the output to a one line status:PASS or FAIL,all of the printf statements
michael@0 17 ** have been handled with an if (debug_mode) statement.
michael@0 18 ** 04-June-97 AGarcia removed the Test_Result function. Regress tool has been updated to
michael@0 19 ** recognize the return code from tha main program.
michael@0 20 **
michael@0 21 ** 12-June-97 AGarcia Revert to return code 0 and 1, remove debug option (obsolete).
michael@0 22 ***********************************************************************/
michael@0 23
michael@0 24
michael@0 25 /***********************************************************************
michael@0 26 ** Includes
michael@0 27 ***********************************************************************/
michael@0 28 #include <stdio.h>
michael@0 29 #include <stdlib.h>
michael@0 30 #include "nspr.h"
michael@0 31
michael@0 32 PRIntn failed_already=0;
michael@0 33 PRIntn debug_mode;
michael@0 34
michael@0 35 /* variable used for both r1 and r2 tests */
michael@0 36 int should_fail =0;
michael@0 37 int actually_failed=0;
michael@0 38
michael@0 39
michael@0 40 void
michael@0 41 r1
michael@0 42 (
michael@0 43 void
michael@0 44 )
michael@0 45 {
michael@0 46 int i;
michael@0 47 actually_failed=0;
michael@0 48 for( i = 0; i < 5; i++ )
michael@0 49 {
michael@0 50 void *x = PR_MALLOC(128);
michael@0 51 if( (void *)0 == x ) {
michael@0 52 if (debug_mode) printf("\tMalloc %d failed.\n", i+1);
michael@0 53 actually_failed = 1;
michael@0 54 }
michael@0 55 PR_DELETE(x);
michael@0 56 }
michael@0 57
michael@0 58 if (((should_fail != actually_failed) & (!debug_mode))) failed_already=1;
michael@0 59
michael@0 60
michael@0 61 return;
michael@0 62 }
michael@0 63
michael@0 64 void
michael@0 65 r2
michael@0 66 (
michael@0 67 void
michael@0 68 )
michael@0 69 {
michael@0 70 int i;
michael@0 71
michael@0 72 for( i = 0; i <= 5; i++ )
michael@0 73 {
michael@0 74 should_fail =0;
michael@0 75 if( 0 == i ) {
michael@0 76 if (debug_mode) printf("No malloc should fail:\n");
michael@0 77 }
michael@0 78 else {
michael@0 79 if (debug_mode) printf("Malloc %d should fail:\n", i);
michael@0 80 should_fail = 1;
michael@0 81 }
michael@0 82 PR_SetMallocCountdown(i);
michael@0 83 r1();
michael@0 84 PR_ClearMallocCountdown();
michael@0 85 }
michael@0 86 }
michael@0 87
michael@0 88 int main(int argc, char **argv)
michael@0 89 {
michael@0 90
michael@0 91 /* main test */
michael@0 92
michael@0 93 PR_Init(PR_USER_THREAD, PR_PRIORITY_NORMAL, 0);
michael@0 94 PR_STDIO_INIT();
michael@0 95 r2();
michael@0 96
michael@0 97 if(failed_already)
michael@0 98 return 1;
michael@0 99 else
michael@0 100 return 0;
michael@0 101
michael@0 102
michael@0 103 }
michael@0 104

mercurial