~ubuntu-branches/ubuntu/precise/code-saturne/precise

« back to all changes in this revision

Viewing changes to tests/bft_mem_test.c

  • Committer: Package Import Robot
  • Author(s): Sylvestre Ledru
  • Date: 2011-11-24 00:00:08 UTC
  • mfrom: (6.1.9 sid)
  • Revision ID: package-import@ubuntu.com-20111124000008-2vo99e38267942q5
Tags: 2.1.0-3
Install a missing file

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
  This file is part of Code_Saturne, a general-purpose CFD tool.
 
3
 
 
4
  Copyright (C) 1998-2011 EDF S.A.
 
5
 
 
6
  This program is free software; you can redistribute it and/or modify it under
 
7
  the terms of the GNU General Public License as published by the Free Software
 
8
  Foundation; either version 2 of the License, or (at your option) any later
 
9
  version.
 
10
 
 
11
  This program is distributed in the hope that it will be useful, but WITHOUT
 
12
  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 
13
  FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
 
14
  details.
 
15
 
 
16
  You should have received a copy of the GNU General Public License along with
 
17
  this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
 
18
  Street, Fifth Floor, Boston, MA 02110-1301, USA.
 
19
*/
 
20
 
 
21
/*----------------------------------------------------------------------------*/
 
22
 
 
23
#include <stdio.h>
 
24
#include <stdlib.h>
 
25
#include <stdarg.h>
 
26
#include <string.h>
 
27
 
 
28
#include <sys/time.h>
 
29
#include <unistd.h>
 
30
 
 
31
#include "bft_error.h"
 
32
#include "bft_mem_usage.h"
 
33
#include "bft_mem.h"
 
34
#include "bft_sys_info.h"
 
35
 
 
36
static void
 
37
bft_mem_error_handler_test(const char     *const file_name,
 
38
                           const int             line_num,
 
39
                           const int             sys_error_code,
 
40
                           const char     *const format,
 
41
                           va_list               arg_ptr)
 
42
{
 
43
  fprintf(stderr, "test memory error handler (empty).\n");
 
44
}
 
45
 
 
46
int
 
47
main (int argc, char *argv[])
 
48
{
 
49
  bft_error_handler_t *errhandler_save;
 
50
 
 
51
  void *p1, *p2, *p3, *p4;
 
52
 
 
53
  /* BFT initialization and environment */
 
54
 
 
55
  bft_mem_usage_init();
 
56
 
 
57
  bft_mem_init("bft_mem_log_file");
 
58
 
 
59
  errhandler_save = bft_mem_error_handler_get();
 
60
 
 
61
  bft_mem_error_handler_set(bft_mem_error_handler_test);
 
62
  printf("test memory error handler set\n");
 
63
 
 
64
  BFT_MALLOC(p1, 100000, long);
 
65
  printf("p1 = %p\n", p1);
 
66
  BFT_MALLOC(p2, 100000, double);
 
67
  printf("p2 = %p\n", p2);
 
68
 
 
69
  p3 = NULL;
 
70
  BFT_REALLOC(p3, 100000, double);
 
71
  printf("p3 = %p\n", p3);
 
72
  BFT_REALLOC(p3, 10000, double);
 
73
  printf("p3 = %p\n", p3);
 
74
 
 
75
  BFT_MALLOC(p4, 5000000000, double);
 
76
  printf("p4 = %p\n", p4);
 
77
 
 
78
  printf("default memory error handler set\n");
 
79
  bft_mem_error_handler_set(errhandler_save);
 
80
 
 
81
  BFT_FREE(p1);
 
82
  BFT_FREE(p2);
 
83
  BFT_MALLOC(p2, 100000, double);
 
84
  printf("p2 = %p\n", p2);
 
85
  BFT_FREE(p2);
 
86
  BFT_REALLOC(p3, 0, double);
 
87
  printf("p3 = %p\n", p3);
 
88
 
 
89
  if (bft_mem_have_memalign() == 1) {
 
90
    void *pa;
 
91
    BFT_MEMALIGN(pa, 128, 100, double);
 
92
    printf("pa (aligned 128) = %p\n", pa);
 
93
    BFT_FREE(pa);
 
94
  }
 
95
 
 
96
  bft_mem_end();
 
97
 
 
98
  printf("max memory usage: %lu kB\n",
 
99
         (unsigned long) bft_mem_usage_max_pr_size());
 
100
 
 
101
  BFT_MALLOC(p1, 10000, long);
 
102
  printf("p1 = %p\n", p1);
 
103
  BFT_FREE(p1);
 
104
  printf("p1 = %p\n", p1);
 
105
  BFT_MALLOC(p1, 1000000000, double);
 
106
  printf("p1 = %p\n", p1);
 
107
 
 
108
  /* End */
 
109
 
 
110
  exit (EXIT_SUCCESS);
 
111
}