mirror of
https://git.savannah.gnu.org/git/grub.git
synced 2026-10-28 01:59:49 +00:00
Merge remote-tracking branch 'origin/master' into phcoder/ports/alpha
This commit is contained in:
commit
5d20f9b0e7
6 files changed
+151
-31
No files matched your search
@@ -1,3 +1,23 @@
|
|||||||
|
2013-10-26 Vladimir Serbinenko <phcoder@gmail.com>
|
||||||
|
|
||||||
|
* tests/date_unit_test.c: New test.
|
||||||
|
|
||||||
|
2013-10-26 Vladimir Serbinenko <phcoder@gmail.com>
|
||||||
|
|
||||||
|
* grub-core/normal/datetime.c (grub_unixtime2datetime): Fix mishandling
|
||||||
|
of first three years after start of validity of unixtime.
|
||||||
|
|
||||||
|
2013-10-26 Vladimir Serbinenko <phcoder@gmail.com>
|
||||||
|
|
||||||
|
* grub-core/normal/menu_entry.c (get_logical_num_lines): Use unsigned
|
||||||
|
division as the one making more sense.
|
||||||
|
(update_screen): Likewise.
|
||||||
|
(complete): Likewise.
|
||||||
|
|
||||||
|
2013-10-25 Vladimir Serbinenko <phcoder@gmail.com>
|
||||||
|
|
||||||
|
* grub-core/normal/menu_entry.c (complete): Make sure that width is >0.
|
||||||
|
|
||||||
2013-10-25 Vladimir Serbinenko <phcoder@gmail.com>
|
2013-10-25 Vladimir Serbinenko <phcoder@gmail.com>
|
||||||
|
|
||||||
Make char and string width grub_size_t rather than grub_ssize_t.
|
Make char and string width grub_size_t rather than grub_ssize_t.
|
||||||
|
|||||||
@@ -899,6 +899,21 @@ program = {
|
|||||||
ldadd = '$(LIBDEVMAPPER) $(LIBZFS) $(LIBNVPAIR) $(LIBGEOM)';
|
ldadd = '$(LIBDEVMAPPER) $(LIBZFS) $(LIBNVPAIR) $(LIBGEOM)';
|
||||||
};
|
};
|
||||||
|
|
||||||
|
program = {
|
||||||
|
testcase;
|
||||||
|
name = date_test;
|
||||||
|
common = tests/date_unit_test.c;
|
||||||
|
common = tests/lib/unit_test.c;
|
||||||
|
common = grub-core/kern/list.c;
|
||||||
|
common = grub-core/kern/misc.c;
|
||||||
|
common = grub-core/tests/lib/test.c;
|
||||||
|
ldadd = libgrubmods.a;
|
||||||
|
ldadd = libgrubgcry.a;
|
||||||
|
ldadd = libgrubkern.a;
|
||||||
|
ldadd = grub-core/gnulib/libgnu.a;
|
||||||
|
ldadd = '$(LIBDEVMAPPER) $(LIBZFS) $(LIBNVPAIR) $(LIBGEOM)';
|
||||||
|
};
|
||||||
|
|
||||||
program = {
|
program = {
|
||||||
testcase;
|
testcase;
|
||||||
name = priority_queue_unit_test;
|
name = priority_queue_unit_test;
|
||||||
|
|||||||
+28
-23
@@ -52,50 +52,55 @@ grub_get_weekday_name (struct grub_datetime *datetime)
|
|||||||
#define SECPERMIN 60
|
#define SECPERMIN 60
|
||||||
#define SECPERHOUR (60*SECPERMIN)
|
#define SECPERHOUR (60*SECPERMIN)
|
||||||
#define SECPERDAY (24*SECPERHOUR)
|
#define SECPERDAY (24*SECPERHOUR)
|
||||||
#define SECPERYEAR (365*SECPERDAY)
|
#define DAYSPERYEAR 365
|
||||||
#define SECPER4YEARS (4*SECPERYEAR+SECPERDAY)
|
#define DAYSPER4YEARS (4*DAYSPERYEAR+1)
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
grub_unixtime2datetime (grub_int32_t nix, struct grub_datetime *datetime)
|
grub_unixtime2datetime (grub_int32_t nix, struct grub_datetime *datetime)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
int div;
|
|
||||||
grub_uint8_t months[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
|
grub_uint8_t months[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
|
||||||
/* In the period of validity of unixtime all years divisible by 4
|
/* In the period of validity of unixtime all years divisible by 4
|
||||||
are bissextile*/
|
are bissextile*/
|
||||||
/* Convenience: let's have 3 consecutive non-bissextile years
|
/* Convenience: let's have 3 consecutive non-bissextile years
|
||||||
at the beginning of the epoch. So count from 1973 instead of 1970 */
|
at the beginning of the counting date. So count from 1901. */
|
||||||
nix -= 3*SECPERYEAR + SECPERDAY;
|
int days_epoch;
|
||||||
|
/* Number of days since 1st Januar, 1901. */
|
||||||
|
unsigned days;
|
||||||
|
/* Seconds into current day. */
|
||||||
|
unsigned secs_in_day;
|
||||||
/* Transform C divisions and modulos to mathematical ones */
|
/* Transform C divisions and modulos to mathematical ones */
|
||||||
div = nix / SECPER4YEARS;
|
|
||||||
if (nix < 0)
|
if (nix < 0)
|
||||||
div--;
|
days_epoch = -(((unsigned) (SECPERDAY-nix-1)) / SECPERDAY);
|
||||||
datetime->year = 1973 + 4 * div;
|
else
|
||||||
nix -= div * SECPER4YEARS;
|
days_epoch = ((unsigned) nix) / SECPERDAY;
|
||||||
|
secs_in_day = nix - days_epoch * SECPERDAY;
|
||||||
|
days = days_epoch + 69 * DAYSPERYEAR + 17;
|
||||||
|
|
||||||
|
datetime->year = 1901 + 4 * (days / DAYSPER4YEARS);
|
||||||
|
days %= DAYSPER4YEARS;
|
||||||
/* On 31st December of bissextile years 365 days from the beginning
|
/* On 31st December of bissextile years 365 days from the beginning
|
||||||
of the year elapsed but year isn't finished yet */
|
of the year elapsed but year isn't finished yet */
|
||||||
if (nix / SECPERYEAR == 4)
|
if (days / DAYSPERYEAR == 4)
|
||||||
{
|
{
|
||||||
datetime->year += 3;
|
datetime->year += 3;
|
||||||
nix -= 3*SECPERYEAR;
|
days -= 3*DAYSPERYEAR;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
datetime->year += nix / SECPERYEAR;
|
datetime->year += days / DAYSPERYEAR;
|
||||||
nix %= SECPERYEAR;
|
days %= DAYSPERYEAR;
|
||||||
}
|
}
|
||||||
for (i = 0; i < 12
|
for (i = 0; i < 12
|
||||||
&& nix >= ((grub_int32_t) (i==1 && datetime->year % 4 == 0
|
&& days >= (i==1 && datetime->year % 4 == 0
|
||||||
? 29 : months[i]))*SECPERDAY; i++)
|
? 29 : months[i]); i++)
|
||||||
nix -= ((grub_int32_t) (i==1 && datetime->year % 4 == 0
|
days -= (i==1 && datetime->year % 4 == 0
|
||||||
? 29 : months[i]))*SECPERDAY;
|
? 29 : months[i]);
|
||||||
datetime->month = i + 1;
|
datetime->month = i + 1;
|
||||||
datetime->day = 1 + (nix / SECPERDAY);
|
datetime->day = 1 + days;
|
||||||
nix %= SECPERDAY;
|
datetime->hour = (secs_in_day / SECPERHOUR);
|
||||||
datetime->hour = (nix / SECPERHOUR);
|
secs_in_day %= SECPERHOUR;
|
||||||
nix %= SECPERHOUR;
|
datetime->minute = secs_in_day / SECPERMIN;
|
||||||
datetime->minute = nix / SECPERMIN;
|
datetime->second = secs_in_day % SECPERMIN;
|
||||||
datetime->second = nix % SECPERMIN;
|
|
||||||
}
|
}
|
||||||
@@ -128,7 +128,7 @@ get_logical_num_lines (struct line *linep, struct per_term_screen *term_screen)
|
|||||||
{
|
{
|
||||||
return (grub_getstringwidth (linep->buf, linep->buf + linep->len,
|
return (grub_getstringwidth (linep->buf, linep->buf + linep->len,
|
||||||
term_screen->term)
|
term_screen->term)
|
||||||
/ term_screen->geo.entry_width) + 1;
|
/ (unsigned) term_screen->geo.entry_width) + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@@ -230,8 +230,8 @@ update_screen (struct screen *screen, struct per_term_screen *term_screen,
|
|||||||
linep = screen->lines + screen->line;
|
linep = screen->lines + screen->line;
|
||||||
grub_size_t t = grub_getstringwidth (linep->buf, linep->buf + screen->column,
|
grub_size_t t = grub_getstringwidth (linep->buf, linep->buf + screen->column,
|
||||||
term_screen->term);
|
term_screen->term);
|
||||||
y += t / term_screen->geo.entry_width;
|
y += t / (unsigned) term_screen->geo.entry_width;
|
||||||
if (t % term_screen->geo.entry_width == 0
|
if (t % (unsigned) term_screen->geo.entry_width == 0
|
||||||
&& t != 0 && screen->column == linep->len)
|
&& t != 0 && screen->column == linep->len)
|
||||||
y--;
|
y--;
|
||||||
/* Check if scrolling is necessary. */
|
/* Check if scrolling is necessary. */
|
||||||
@@ -1029,12 +1029,14 @@ complete (struct screen *screen, int continuous, int update)
|
|||||||
if (restore)
|
if (restore)
|
||||||
for (i = 0; i < screen->nterms; i++)
|
for (i = 0; i < screen->nterms; i++)
|
||||||
{
|
{
|
||||||
int width = grub_term_width (screen->terms[i].term) - 2;
|
unsigned width = grub_term_width (screen->terms[i].term);
|
||||||
|
if (width > 2)
|
||||||
|
width -= 2;
|
||||||
if (width > 15)
|
if (width > 15)
|
||||||
width -= 6;
|
width -= 6;
|
||||||
int num_sections = ((completion_buffer.len
|
unsigned num_sections = ((completion_buffer.len
|
||||||
+ width - 1)
|
+ width - 1)
|
||||||
/ width);
|
/ width);
|
||||||
grub_uint32_t *endp;
|
grub_uint32_t *endp;
|
||||||
struct grub_term_coordinate pos;
|
struct grub_term_coordinate pos;
|
||||||
grub_uint32_t *p = ucs4;
|
grub_uint32_t *p = ucs4;
|
||||||
@@ -1080,7 +1082,7 @@ complete (struct screen *screen, int continuous, int update)
|
|||||||
grub_puts_terminal ("\n ", screen->terms[i].term);
|
grub_puts_terminal ("\n ", screen->terms[i].term);
|
||||||
}
|
}
|
||||||
|
|
||||||
p += (count % num_sections) * width;
|
p += ((unsigned) count % num_sections) * width;
|
||||||
endp = p + width;
|
endp = p + width;
|
||||||
|
|
||||||
if (p != ucs4)
|
if (p != ucs4)
|
||||||
|
|||||||
@@ -129,6 +129,8 @@ typedef grub_int32_t grub_ssize_t;
|
|||||||
#define GRUB_SHRT_MAX 0x7fff
|
#define GRUB_SHRT_MAX 0x7fff
|
||||||
#define GRUB_UINT_MAX 4294967295U
|
#define GRUB_UINT_MAX 4294967295U
|
||||||
#define GRUB_INT_MAX 0x7fffffff
|
#define GRUB_INT_MAX 0x7fffffff
|
||||||
|
#define GRUB_INT32_MIN (-2147483647 - 1)
|
||||||
|
#define GRUB_INT32_MAX 2147483647
|
||||||
|
|
||||||
#if GRUB_CPU_SIZEOF_LONG == 8
|
#if GRUB_CPU_SIZEOF_LONG == 8
|
||||||
# define GRUB_ULONG_MAX 18446744073709551615UL
|
# define GRUB_ULONG_MAX 18446744073709551615UL
|
||||||
|
|||||||
@@ -0,0 +1,76 @@
|
|||||||
|
/*
|
||||||
|
* GRUB -- GRand Unified Bootloader
|
||||||
|
* Copyright (C) 2013 Free Software Foundation, Inc.
|
||||||
|
*
|
||||||
|
* GRUB is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* GRUB is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <time.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#include <grub/misc.h>
|
||||||
|
#include <grub/datetime.h>
|
||||||
|
#include <grub/test.h>
|
||||||
|
|
||||||
|
static void
|
||||||
|
date_test (grub_int32_t v)
|
||||||
|
{
|
||||||
|
struct grub_datetime dt;
|
||||||
|
time_t t = v;
|
||||||
|
struct tm *g;
|
||||||
|
int w;
|
||||||
|
|
||||||
|
g = gmtime (&t);
|
||||||
|
|
||||||
|
grub_unixtime2datetime (v, &dt);
|
||||||
|
|
||||||
|
w = grub_get_weekday (&dt);
|
||||||
|
|
||||||
|
grub_test_assert (g->tm_sec == dt.second, "time %d bad second: %d vs %d", v,
|
||||||
|
g->tm_sec, dt.second);
|
||||||
|
grub_test_assert (g->tm_min == dt.minute, "time %d bad minute: %d vs %d", v,
|
||||||
|
g->tm_min, dt.minute);
|
||||||
|
grub_test_assert (g->tm_hour == dt.hour, "time %d bad hour: %d vs %d", v,
|
||||||
|
g->tm_hour, dt.hour);
|
||||||
|
grub_test_assert (g->tm_mday == dt.day, "time %d bad day: %d vs %d", v,
|
||||||
|
g->tm_mday, dt.day);
|
||||||
|
grub_test_assert (g->tm_mon + 1 == dt.month, "time %d bad month: %d vs %d", v,
|
||||||
|
g->tm_mon + 1, dt.month);
|
||||||
|
grub_test_assert (g->tm_year + 1900 == dt.year,
|
||||||
|
"time %d bad year: %d vs %d", v,
|
||||||
|
g->tm_year + 1900, dt.year);
|
||||||
|
grub_test_assert (g->tm_wday == w, "time %d bad week day: %d vs %d", v,
|
||||||
|
g->tm_wday, w);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
date_test_iter (void)
|
||||||
|
{
|
||||||
|
grub_int32_t tests[] = { -1, 0, +1, -2133156255, GRUB_INT32_MIN,
|
||||||
|
GRUB_INT32_MAX };
|
||||||
|
unsigned i;
|
||||||
|
|
||||||
|
for (i = 0; i < ARRAY_SIZE (tests); i++)
|
||||||
|
date_test (tests[i]);
|
||||||
|
srand (42);
|
||||||
|
for (i = 0; i < 1000000; i++)
|
||||||
|
{
|
||||||
|
grub_int32_t x = rand ();
|
||||||
|
date_test (x);
|
||||||
|
date_test (-x);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
GRUB_UNIT_TEST ("date_unit_test", date_test_iter);
|
||||||
Reference in new issue
Block a user